[英]Regex to match very occurrence in string
I have a string "Format: Multiple videos Length:20 mins ....Format: Video with Length: 50 mins"
and want to enclose "Format ...mins" part in a tag eg我有一个字符串
"Format: Multiple videos Length:20 mins ....Format: Video with Length: 50 mins"
并希望将“格式 ...分钟”部分包含在标签中,例如
"<p>Format: Multiple videos Length:20 mins</p> ....<p>Format: Video with Length: 50 mins</p>"
The regex I have in Coldfusion is我在 Coldfusion 中的正则表达式是
<cfset str= reReplace(str, "Format:(.*?)Video(.*?)mins", "<p>Format:\1Video\2mins</p>", "ALL")>
but I get output as但我得到的输出为
"<p>Format: Multiple videos Length:20 mins ....Format: Video with Length: 50 mins</p>"
What is the proper regex to match every occurrence in the string?匹配字符串中每次出现的正确正则表达式是什么?
You can use您可以使用
REReplaceNoCase(str, "Format:((?:(?!Format:|Video|mins).)*)Video((?:(?!Format:|mins).)*)mins", "<p>Format:\1Video\2mins</p>", "ALL")
See the regex demo .请参阅正则表达式演示。
Details :详情:
REReplaceNoCase
- case insensitive regex replace function REReplaceNoCase
- 不区分大小写的正则表达式替换功能Format:
- a fixed string Format:
- 固定字符串((?:(?!Format:|Video|mins).)*)
- Group 1: any text up to the first Video
that has no Format:
, Video
and mins
substrings ((?:(?!Format:|Video|mins).)*)
- 第 1 组:直到第一个没有Format:
、 Video
和mins
子字符串的Video
的任何文本Video
- a fixed string Video
- 固定字符串((?:(?!Format:|mins).)*)
- Group 2: any text up to the first mins
that has no Format:
and mins
substrings ((?:(?!Format:|mins).)*)
- 第 2 组:前mins
之前没有Format:
和mins
子字符串的任何文本mins
- a fixed string mins
- 固定字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.