#9744
JohnQSmith
Participant

I see the problem with both of your tests. It’s the same thing that took me so long to figure out how it works.

Here’s the key…
The whole RegEx must match in order for it to work. In other words, you have to set up the RegEx with an alternation so that it has both a success and a failure point.

In your first test, only the first line matched your RegEx (I’m using underscores as filler to demonstrate).


Test Price 100______0
(.+) (.+) (d{3}) (d) <-- this matches

Test Price 100________
(.+) (.+) (d{3}) (d) <-- this doesn't match, there is no final (d)

Test Price 800________
(.+) (.+) (d{3}) (d) <-- also doesn't match

Here’s how I changed your RegEx to work.


Note the success ----. and failure points
| |
v v
Find: ^(.+) (.+) (d{3})(?:(d)|$)
Replace: (?4:too expensive:affordable)

Your second example is the same thing.


Color_ 1__ green
(Color d) (.+) <-- match

Color_ 2__ blue
(Color d) (.+) <-- match

Color_ 3__ red
(Color d) (.+) <-- match

The available colors are either green, blue or red.
(Color d) (.+) <-- no match anywhere on line

Hope this helps.