[英]regex match not if in the same line
I have created a regex that match my custom html tag.我创建了一个与我的自定义 html 标签匹配的正则表达式。 For example:
例如:
<var-input id="" kind="{"id":2,"art":"TEXT","name":"Textfeld","default":null}" choices="1,2,3,four" value="radio not text"></var-input>
The html-tag always have the form <var-input id="" kind="" choices="" value=""></var-input>
html 标签的形式总是
<var-input id="" kind="" choices="" value=""></var-input>
And these are the restrictions:这些是限制:
id
is an uuid4 string or empty id
是一个 uuid4 字符串或空kind
is a JSON stringify object kind
是一个 JSON 字符串化对象choices
is an array (comma separated) or empty choices
是一个数组(逗号分隔)或空value
is a string or empty value
字符串或空This is my regex now:这是我现在的正则表达式:
<var-input id=\"([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})?\" kind=\"({.*})\" choices=\"([a-zA-Z0-9_,\s]*)\" value=\"([a-zA-Z0-9_,\s]*)\"></var-input>
It works good for one match like the above example.它适用于像上面的例子一样的一场比赛。 But is there more than one
<var-input ...></var-input>
in one line, the regex not work correct.但是在一行中有多个
<var-input ...></var-input>
时,正则表达式不能正常工作。 Why?为什么?
Just make {.*}
not greedy: {.*?}
.只是让
{.*}
不贪婪: {.*?}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.