user350233
user350233

Reputation: 139

Need a better regex for group matching

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

Thanks you in advance,

Su

Upvotes: 1

Views: 62

Answers (2)

Ben Hoffstein
Ben Hoffstein

Reputation: 103345

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

Upvotes: 0

Ahmad Mageed
Ahmad Mageed

Reputation: 96487

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

Upvotes: 3

Related Questions