开发者

Capturing all matching groups rather than 1

开发者 https://www.devze.com 2022-12-07 20:59 出处:网络
I am attempting to capture all matching groups rather than 1. Turing > 128 gb Apple iPhone SE (AiSE) 128 gb Apple iPhone SE (AiSE)

I am attempting to capture all matching groups rather than 1.

Turing > 128 gb Apple iPhone SE (AiSE) 128 gb Apple iPhone SE (AiSE)

I am using the following regex:

\b(\w+)\b(?=.*?\b\1\b)

but it is still开发者_开发知识库 not working. Can someone please help me capture all matching groups rather than 1?


We can try matching on the following regex pattern:

\d+ [a-z]b(?: \S+)*?(?= \d+ [a-z]b\b|$)

Explanation:

  • \d+ match a memory size
  • single space
  • [a-z]b size units (e.g. gb)
  • (?: \S+)*? then match any number of following terms until asserting that
  • (?=
    • \d+ [a-z]b\b space followed by another memory term follows
    • | OR
    • $ the end of the string follows
  • )

Here is a link to a regex demo.

0

精彩评论

暂无评论...
验证码 换一张
取 消