简体   繁体   English

如果在同一行,则正则表达式不匹配

[英]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="{&quot;id&quot;:2,&quot;art&quot;:&quot;TEXT&quot;,&quot;name&quot;:&quot;Textfeld&quot;,&quot;default&quot;: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?为什么?

Here is an example这是一个例子

Just make {.*} not greedy: {.*?} .只是让{.*}不贪婪: {.*?}

Updated demo更新演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM