2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

お尻(単語末尾)が欠けている正規表現は否定的先読み

Posted at

たとえば、正常な「Qiita」が含まれる文中で、「Qiit」という文字列を検出したい。

結論

否定的先読みがそういう用途。

qiit(?!a)

ぱっと思いつくもの

qiit(?:[^a]|$)

行末の場合ならいいが、行中なら余計な「a以外の文字」までmatchした文字列として検出される。

参考

否定的先読み(?!pattern)

次の正規表現では直後にbarがないfoo(barは含まない)に一致します.
foo(?!bar)

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?