3

A regexp that will grab anything in quotes + the word draft within the quotes. So it will look for the word Draft and upon finding it grab everything in front of it and behind it within the quotes. For example:

1) "earth is beautiful"

2) "My Second Draft"

In the above examples the regexp will only grab the second example, highlighting everything within the quotes. How can this be accomplished?

Thank you.

4

2 に答える 2

4

これを使用できるはずです:

\"[^\"]*(d|D)(r|R)(a|A)(f|F)(t|T)[^\"]*\"

説明:

  • \""-キャラクターと一致する
  • [^\"]*"-シーケンス内の文字が文字でない限り、任意の文字シーケンスに一致します
  • (d|D)(r|R)(a|A)(f|F)(t|T)-大文字と小文字を区別しない「ドラフト」という単語に一致
  • [^\"]*"-シーケンス内の文字が文字でない限り、任意の文字シーケンスに一致します
  • \""-キャラクターと一致する

使用している言語によっては、正規表現を大文字と小文字を区別しないものとして扱う必要があることを示している限り、(d|D)(r|R)(a|A)(f|F)(t|T)シーケンスを削除して置き換えることができるはずです。draft

Javascriptを使用しているため、正規表現リテラルは次のようになります。

/\"[^\"]*draft[^\"]*\"/i
于 2013-03-20T15:49:17.517 に答える
2

このパターンはあなたのために働くはずです

/\"((draft.*)|(.*draft.*)|(.*draft))\"/Ui
于 2013-03-20T15:56:50.380 に答える