在两个起始和结束参数之间查找文本匹配。

huangapple go评论62阅读模式
英文:

Find text match between two start and end parameters

问题

正则表达式 (color[^$]*blue)

期望结果:

  1. color Dolores ducimus nulla doloribus quod odit modi perspiciatis delectus earum nisi, sit ex! blue
  2. COLOR deleniti iure ipsam beatae nostrum vel dolore dolorum id esse inventore eligendi velit ut temporibus eius in, BLUE
  3. colorpraesentium accusamus, magnam nesciunt cumque fugiat nonblue
英文:

I would like to know if there is a more optimal or the most efficient literal to match all variants to find all the conicidences of a text, passing two params (start, end), regardless of the internal characters.

REGEX (color[^$]*blue)

Lorem ipsum dolor, sit amet consectetur adipisicing elit. color Dolores ducimus nulla doloribus quod odit modi perspiciatis delectus earum nisi, sit ex! blue Doloribus dolores provident hic consequuntur natus ipsa inventore expedita!
Fugit autem saepe fuga maiores quo optio exercitationem reiciendis COLOR deleniti iure ipsam beatae nostrum vel dolore dolorum id esse inventore eligendi velit ut temporibus eius in, BLUE corrupti laboriosam modi. Excepturi.
Iure maiores, fuga neque vitae est repellendus colorpraesentium accusamus, magnam nesciunt cumque fugiat nonblue impedit! Laborum exercitationem architecto fugiat libero eaque provident voluptatem aperiam unde nulla impedit porro, itaque nisi.

Expected result

  1. color Dolores ducimus nulla doloribus quod odit modi perspiciatis delectus earum nisi, sit ex! blue
  2. COLOR deleniti iure ipsam beatae nostrum vel dolore dolorum id esse inventore eligendi velit ut temporibus eius in, BLUE
  3. colorpraesentium accusamus, magnam nesciunt cumque fugiat nonblue

答案1

得分: 1

如果您期望的结果是您想要的,这应该是您的解决方案:
https://regexr.com/4rjt3

标志 "i" 将使正则表达式不区分大小写。

请注意 - 我将 [^$] 替换为 (.*),以便您可以单独获取结果。

英文:

If the expected result is what you want, this is should be your solution:
https://regexr.com/4rjt3

The flag "i", will make the regex not case sensitive.

Please notice - I replaced [^$] with (.*) so you will get the results separately.

答案2

得分: 1

这匹配了从"color"到"blue"之间的所有内容(包括它们),没有"color"或"blue"之间的内容:

(?i)color(?:(?!color|blue).)*blue

演示和解释

英文:

This matches all between color and blue (included) with no color or blue in between:

(?i)color(?:(?!color|blue).)*blue

Demo & explanation

huangapple
  • 本文由 发表于 2020年1月4日 00:51:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定