我想构建两个选择的正则表达式:
以'religion'开头的行。我试试/^religion/g
但是我
没有结果
匹配日期和内容。例如:867.1.1 = {b_reykjavik = tb_shipyard_1}
我尝试\d{3}\.([1-12])\.([1-31]) = {
这会选择867.1.1 = {
。
现在,如何选择其他字符直到}
?示例:https://www.debuggex.com/r/GloZ8dZDVLJ5jc29
案文是:
# 1 - Vestisland
b_reykjavik = tribal
#b_alftanes = city
#b_skalholt = temple
#b_pingvellir = castle
#b_kjalarnes = castle
#b_hvamm = castle
#b_hlidarendi = castle
#b_borg = castle
# Misc
culture = norse
religion = zoroastrian
terrain = arctic
# History
867.1.1 = {
b_reykjavik = tb_shipyard_1
}
900.1.1 = {
b_reykjavik = castle
b_reykjavik = ca_shipyard_1
b_alftanes = city
}
1000.1.1 = {
culture = norwegian
religion = zoroastrian = sunni = catholic
}
答案 0 :(得分:1)
您可以使用
/^(?:religion.*|\d+(?:\.\d+){2} = {[^}]*})/gm
<强>详情:
^
- 一行的开头(因为m
修饰符使^
在一行的开头匹配)(?:religion.*
- 备选方案1:religion
后跟除了换行符之外的任何0 +字符|
- 或\d+(?:\.\d+){2} = {[^}]*})
- 1位数字,后跟2个.
+一个或多个数字的序列(请参阅\d+(?:\.\d+){2}
),然后是空格,=
,空格,{ {1}},除{
之外的零个或多个字符(请参阅}
)和[^}]*
。要仅抓取部分记录,请在这些子图案周围使用捕获组(}
),请参阅following regex:
(...)
/^(?:religion = (.*)|\d+(?:\.\d+){2} = {([^}]*)})/gm
^ ^ ^ ^
&#13;