で囲まれた文字列を含むテキストがあります#[ ]
。これらの文字列を照合して、内部の文字列を見つける必要があります。
私のテキスト例:
Lorem ipsum dolor #[This is my first string.] sit amet, consectetur elit,
sed do eiusmod tempor incididunt #[This is my second string?] ut et dolore magna.
このテキストでは、2 つの一致が必要です。
#[This is my first string.]
#[This is my second string?]
今、正規表現を書きました:
\#\[([\w\s\W]*)\]
\W
ドット、クエスチョン マーク、その他の文字以外の文字を含めたいので、追加しました。now #
、[
and]
が含まれているため、テキストに一致するものが1つしかないため、これにより問題が発生します。
#[This is my first string.] sit amet, consectetur elit,
sed do eiusmod tempor incididunt #[This is my second string?]
もちろん、 の最初の出現#[
と最後の出現に一致し]
ます。これを解決する方法は?#
文字列に, [
andを含めないことを受け入れることができ]
ますが、可能であれば、他のすべての文字以外の文字を含める必要があります。