2

私はこのテキストを持っています:

{{Infobox Item
|name = value
|prop2 = value
|prop3 = value
}}

これは、mediawiki テンプレートからのものです。

私は次の正規表現を持っています:

preg_match('/\{\{Infobox Item.+\\n\}\}\\n/s', $text, $ra);

私はPHPを使用しています。

常に単独で行にある{{Infobox Item最初の出現までを一致させたいです。}}上記の正規表現は、別のスタイル ブロック{{Infobox Itemの最後まで一致しますが、これは私が望んでいるものではありません。{{ }}どうすればこれを達成できますか?

4

1 に答える 1

1

コード

preg_match('/{{Infobox Item.+?^}}$/sm', $subject, $regs)

正規表現

{{Infobox Item.+?^}}$

正規表現の視覚化

https://regex101.com/r/gC0oV1/1

人間が読める

# {{Infobox Item.+?^}}$
# 
# Options: Case sensitive; Exact spacing; Dot matches line breaks; ^$ match at line breaks; Greedy quantifiers
# 
# Match the character string “{{Infobox Item” literally (case sensitive) «{{Infobox Item»
# Match any single character «.+?»
#    Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
# Assert position at the beginning of a line (at beginning of the string or after a line break character) (line feed) «^»
# Match the character string “}}” literally «}}»
# Assert position at the end of a line (at the end of the string or before a line break character) (line feed) «$»
于 2015-12-12T23:32:40.487 に答える