Regular Expression: using \1 twice
Posted: Mon Oct 15, 2001 5:55 am
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.
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.