0
votes

Guys I want to write regex that matches all those strings starting with lower or ground and end with flat.. i.e. both these two would be captured in their entirety.

Example:

LOWER GROUND FLAT

GROUND FLAT

However, this does not seem to be doing the job:

^LOWER|GROUND\sFLAT$

1

1 Answers

3
votes

You should be using:

^(LOWER|GROUND)\s+.*?FLAT$

As you wrote it like

^LOWER|GROUND\sFLAT$

it is basically trying to match either

^LOWER

or

GROUND\sFLAT$

The parentheses change that to your original intent.