EmEditor (text editor) Forum Index Regular Expressions
Example please for (?n:true_expression:false_expression) | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| Stefan | Posted on: 10/13/2011 10:51 pm |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Example please for (?n:true_expression:false_expression) How can i utilize this feature please?
(?n:true_expression:false_expression) Found at: http://www.emeditor.com/modules/feature1/rewrite/tc_35.html EmEditor Professional 9 New Features The replace format "(?n:true_expression:false_expression)" was added to regular expression replace formats. |
| JohnQSmith | Posted on: 10/17/2011 12:10 pm |
Not too shy to talk ![]() ![]() Joined: 7/15/2011 From: Posts: 30 |
Re: Example please for (?n:true_expression:false_expression) I played with it a while and finally figured it out. Here's an example.
Input document Search string Replace string Replace all and output is I color coded it to help you see what's happening. Oh yeah, the Boost regex docs helped me figure it out. |
| Stefan | Posted on: 10/17/2011 9:46 pm |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Re: Example please for (?n:true_expression:false_expression) Thanks John! I see it, but i don't understand it. Will have an closer look and read the Boost help... |
| Stefan | Posted on: 10/17/2011 11:18 pm |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Re: Example please for (?n:true_expression:false_expression) Quote:
Seams clear, but i have still problems using this. Some tests: OK, i will test some more. |
| 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). Here's how I changed your RegEx to work. Your second example is the same thing. Hope this helps. |
| Stefan | Posted on: 10/18/2011 10:12 am |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Re: Example please for (?n:true_expression:false_expression) Thank you.
My understanding right now: You have to set up the FIND RegEx with an alternation so that it has both a success and a failure point. As the REPLACE have too possibilities too: (?n:true_expression:false_expression) Test: Thanks again. I still have to do some test, but i think you showed me the way. - BTW, good idea of you:Replace: \0 (?4:too expensive:affordable) - |
| JohnQSmith | Posted on: 10/18/2011 10:39 am |
Not too shy to talk ![]() ![]() Joined: 7/15/2011 From: Posts: 30 |
Re: Example please for (?n:true_expression:false_expression) Quote:
My understanding right now: Absolutely correct. I like your FIND RegEx better. It will be much easier to use than mine. Just adding the zero or more switch makes it much simpler than a non-matching alternation grouping. What helped me the most in figuring out how it works was how EmEditor highlights all matches when you do a search. When I tried your first search, only the first "Test Price" line was highlighted, but when I removed the final "(\d)", all the lines were marked. This showed me that the problem was with the RegEx. The first and foremost thing to remember is that the WHOLE RegEx expression must match before you can do any further matching and testing with a SUBexpression. Quote: BTW, good idea Thanks! ![]() |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |





of you: