Regular Expression: using \1 twice

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Luoji

Regular Expression: using \1 twice

Post by Luoji »

Hello,

I want to duplicate a line and modify only a part of it. I used the following regular expressions in POSIX to replace my line but it didn't work:

replace: command ([.]*)
by: command \1\nnewcommand \1

---

Example:

text to replace:
command attributes
command other attributes

expected result:
command attributes
newcommand attributes
command other attributes
newcommand other attributes

result with my regexp:
command
newcommand attributes
command
newcommand other attributes

---

How come that \1 is only applied at the last occurence?

Regards,


Luoji.
Jens Hollmann

Re: Regular Expression: using \1 twice

Post by Jens Hollmann »

Very interesting! Don't put "[]" around the "." and it works! I don't know exactly why but the "[]" are at least not necessary because "." already matches any character.
Andreas

Re: Regular Expression: using \1 twice

Post by Andreas »

[.] matches a . and nothing else
while . matches any character

Within [], most special characters are not special any longer!

See Help/Help Topics/Contents/Reference Information/Regular Expressions/Special Characters
Post Reply