EmEditor (text editor) Forum Index EmEditor Core Bug Reports
Find/Replace: Multiple replaces needed when using Replace All | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| Deipotent | Posted on: 10/13/2011 2:57 pm |
Just can't stay away ![]() ![]() Joined: 2/15/2008 From: Posts: 122 |
Find/Replace: Multiple replaces needed when using Replace All If you have a line with the text:
and do a regex Find for and replace with you have to do Replace All twice. The first time will result in The second pass changes ",3," to ",03,". Why is the ",3," not done in the first pass ? Is this a bug ? |
| Stefan | Posted on: 10/14/2011 12:01 am |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 265 |
Re: Find/Replace: Multiple replaces needed when using Replace All .
Hi Me thinks that is how the regex engine works? You search ",\d," on an string like "10,6,3,12" The regex will match ",6," then it continuous at the very next sign from the rest of the string which is now "3,12". As you see your search pattern will not match on "3,12" because there is no ",\d," anymore. The trick is to not match the comas itself as you do but only take an look if they are present. That can be fine done by using positive lookbehind and lookahead which EmEditor supports (thanks Yutaka). For more info about that feature see e.g.: http://www.regular-expressions.info/lookaround.html Example: search pattern: "oogl" positive lookbehind if there is an "G" right before your search pattern: (?<=G) positive lookahead if there is an "e" just after your search pattern: (?=e) So RegEx search for: (?<=G)oogl(?=e) Will match: Woogle Googlo Foogle Example for your issue with commas: (?<=,)(\d)(?=,) 0\1 HTH? . |
| Deipotent | Posted on: 10/14/2011 4:03 pm |
Just can't stay away ![]() ![]() Joined: 2/15/2008 From: Posts: 122 |
Re: Find/Replace: Multiple replaces needed when using Replace All Thanks for the detailed answer Stefan!
Didn't know the characters were consumed by default, but lookbehind and lookahead does indeed solve the problem. Thanks again! ![]() |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |




