开发者

Need a better regex for group matching

开发者 https://www.devze.com 2023-01-01 13:15 出处:网络
Presently I\'m using two regx: ABC.*1EFG ABC.*2HIJ to retrieve Line 1 and Line 2 from a text file. Is there a better single regex, so that both the lines(L1 and L2) from below can be matched.

Presently I'm using two regx:

ABC.*1EFG

ABC.*2HIJ

to retrieve Line 1 and Line 2 from a text file. Is there a better single regex, so that both the lines(L1 and L2) from below can be matched.

Line 1: ABCanystring1EFGanystring

Line 2: ABCanystring2HIJanystring

Line 3: ABCanystring2LMNanystring

.

.


.
Line n

Tha开发者_如何转开发nks you in advance,

Su


Use this pattern: ABC.*(1EFG|2HIJ)


If you want to match the whole line, you can use ^ABC\s*(1EFG|2HIJ).*$

0

精彩评论

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

关注公众号