-1

ユーザー入力のリンク構造:

++visible part of link====invisible HTML address part of link++

入力文字列:

some text here some text here ++stack overflow====http://stackoverflow.com/questions/ask++ some text here ++examplesite.com====http://www.examplesite.com/article?id=1++ some text here some text here some text here some text here ++shouldnotmatch.com====http://w ww.shouldnotmatch.com/++ some text here.

私の目的:

====との間の部分++に 1 つ以上のスペース文字が含まれている場合、preg_match_all一致しないはずです。したがって、私の望ましい出力は、最初の 2 つのリンク試行と一致することです。w wwただし、 1 つの空白文字が含まれているため、最後のリンク試行は一致しないはずです。

私の失敗した試み:

  1. \+\+(.+?)====(.+?[^ ])\+\+
  2. \+\+(.+?)====(.+?[^ {1, }])\+\+

訂正していただけますか?

4

2 に答える 2

1

この正規表現を試してください:

[+]{2}(.+?)[=]{4}([^\s]+?)[+]{2}
于 2013-03-28T09:42:47.500 に答える
1

最初の試行では、スペース検証の前にすべての文字を許可していました。

このようなものは機能しますか?

!\+\+(.+?)====([^ ]+?)\+\+!

これらの括弧の間に常に何かがある場合は、? を削除できます。

!\+\+(.+?)====([^ ]+)\+\+!
于 2013-03-28T09:40:13.023 に答える