EmEditor (text editor) Forum Index Regular Expressions
RegExp OR function misbehaviour ? | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| Salabim | Posted on: 9/9/2009 9:03 pm |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
RegExp OR function misbehaviour ? Hi,
I have a problem with a macro I created which consists of 1 line : ... having the line : denkje wilje dachtje kanje wildeje zieje ... I expected it would replace it like this : denk je wil je dacht je kan je wilde je zie je ... but I only replaced the 1st, 3rd, and 5th match, like this : denk je wilje dacht je kanje wilde je zieje Why doesn't it replace the 2nd (wilje) the 4th (kanje) and the 6th (zieje) item please ? |
| Salabim | Posted on: 9/11/2009 7:34 am |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? Really nobody ?
|
| Yutaka | Posted on: 9/11/2009 9:57 am |
Webmaster ![]() ![]() Joined: 9/28/2006 From: Redmond Posts: 2398 |
Re: RegExp OR function misbehaviour ? Quote:
Is it possible to make your sample as simple as possible? That will make it easy to reproduce the issue. Thanks!
|
| Salabim | Posted on: 9/11/2009 11:21 am |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? Hello Yutaka,
I'm trying to make it as easy as possible, I just want to check for any of these combo's and put a space between them and je, only if these are surrounded by a space or are at the beginning or end of a line. So.... I don't think I can make it simpler than that. |
| thr | Posted on: 9/12/2009 10:26 am |
Just popping in ![]() ![]() Joined: 9/12/2009 From: Posts: 3 |
Re: RegExp OR function misbehaviour ? Try this:
|
| Salabim | Posted on: 9/12/2009 3:39 pm |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? Aaaaagh! Exactly, shame on me that I didn't think about that.
After all, I'm a real newbie regarding regexp's, Only problem, I use bot the first (newline OR space) and the last (newline OR space) in the replacement as \1 and \3 , that means the ?= will NOT assign the following newline or space to \3 ? so with the replacement line of \1\2 je\3 \3 will be empty even if there IS a space or newline after "je", am I right ? Thanks for the help! |
| thr | Posted on: 9/12/2009 11:22 pm |
Just popping in ![]() ![]() Joined: 9/12/2009 From: Posts: 3 |
Re: RegExp OR function misbehaviour ? Yes, a positive lookahead only matches, it doesn't "consume" anything. But you can simplify your whole construct like so:
That way you don't need to pay attention to matching the word separators at all. That gives you a lot more leeway. For example, you can then have something like and it will still work as intended, while keeping all word separators intact. Even more simpler with the word shorthand class: |
| Salabim | Posted on: 9/13/2009 5:41 am |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? Thank you very much for the detailed explanation thr !
I owe you one ! |
| Salabim | Posted on: 9/13/2009 8:01 am |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? EDIT:
Second line error'ed out, missing ). Even when corrected, doesn't do anything. First line did it completely wrong also, even when I corrected thr's suggestions to have double backslashes, and correct (). It's not the aspect of simplifying things for example to match a whole word followed by [je], I need to use the words in my top post matched, since those MAY NEVER be followed by [je], only when there's a space in between. Other words can be followed directly by je, since I'm correcting Dutch texts, and there je at the end of a word means "little" in English. So, these words translated from Dutch to English. Pak = Box Pakje = Little box Kind = Child Kindje = Little child Hond = Dog Hondje = Little dog ... but Denk = Think Wil = Want Dacht = Thought .... so above cannot be followed by [je] since that is not correct, there doesn't exist any little think, or little want, or little thought. Please, can anyone help me out ? P.S. Sorry for my bad English. |
| Salabim | Posted on: 9/13/2009 9:00 am |
Quite a regular ![]() ![]() Joined: 9/5/2009 From: Ghent (Belgium) Posts: 58 |
Re: RegExp OR function misbehaviour ? Sorry if this all sounds so difficult, the biggest problem is my little knowledge of English to explain the problem
properly, and of course I'm far from a pro into brewing regular expressions. Perhaps, I can give some kind of English example that gives an idea of what I mean. So, In English, correcting the following line(s) properly. Is that possible to properly correct with 1 single line of regexp ? English example : I wantto lookto the car, while doing a salto justto celebrate how great is it. with the example above, you cannot simple say : Look for any word that ends with to and put a space inbetween it, because then the word salto would improperly been turn apart. And of course, checking that the words to search for, are indeed surrounded by a space or a comma, or a newline, is not possible too, because in the English example I gave the space after wantto is being captured, so the regexp doesn't correct the lookto right after it, because there it doesn't see the preceding space because it is handled by the match before it. So, what can I do, I guess I can only write all my regexp's double, or is there any special switch to make it work correctly with 1 line of regexp ? EDIT: before you say look to is not correct and has to be look at, I know ! it'sonly just to give an example. |
| (1) 2 » | |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |





