EmEditor (text editor) Forum Index
   Regular Expressions
     Example please for (?n:true_expression:false_expression)
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
JohnQSmith
Posted on: 10/18/2011 6:39 am
Not too shy to talk
Joined: 7/15/2011
From:
Posts: 30
Re: Example please for (?n:true_expression:false_expression)
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: \0 (?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.
Flat Previous Topic | Next Topic


Subject Poster Date
   Example please for (?n:true_expression:false_expression) Stefan 10/13/2011 10:51 pm
     Re: Example please for (?n:true_expression:false_expression) JohnQSmith 10/17/2011 12:10 pm
       Re: Example please for (?n:true_expression:false_expression) Stefan 10/17/2011 9:46 pm
         Re: Example please for (?n:true_expression:false_expression) Stefan 10/17/2011 11:18 pm
         » Re: Example please for (?n:true_expression:false_expression) JohnQSmith 10/18/2011 6:39 am
             Re: Example please for (?n:true_expression:false_expression) Stefan 10/18/2011 10:12 am
               Re: Example please for (?n:true_expression:false_expression) JohnQSmith 10/18/2011 10:39 am

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文