Page 1 of 1

Regular expression to change line of text

Posted: Mon Apr 04, 2022 5:04 pm
by dforrest
Can someone please help me with a regular expression to change multiple instances of:

FileName ( ../../Routes/Watersnake/Alias/xyz1234.s )

in a file to:

FileName ( "../../Routes/Watersnake/Alias/xyz1234.s" )

xyz1234 is different in content and length in each expression and should remain unchanged. The remainder is the same in all expressions and should be repeated as it is.

Thank you.

Posted: Mon Apr 04, 2022 9:19 pm
by ben_josephs
Depending the exact details of what is to be replaced, this might do it:

Find what: FileName \( ([^)]+) \)
Replace with: FileName \( "$1" \)

Posted: Mon Apr 04, 2022 9:36 pm
by dforrest
ben_josephs wrote:Depending the exact details of what is to be replaced, this might do it:

Find what: FileName \( ([^)]+) \)
Replace with: FileName \( "$1" \)
Thanks but it adds the quotes for all lines with a format like

FileName ( xxxxx.s )

I really only need to replace lines with ../../Routes/Watersnake/Alias included in them.

If that is not possible, what you have provided should be acceptable.

Posted: Mon Apr 04, 2022 9:59 pm
by ben_josephs
Find what: FileName \( (\.\./\.\./Routes/Watersnake/Alias/[^)]+) \)
Replace with: FileName \( "$1" \)

Posted: Mon Apr 04, 2022 11:00 pm
by dforrest
ben_josephs wrote:Find what: FileName \( (\.\./\.\./Routes/Watersnake/Alias/[^)]+) \)
Replace with: FileName \( "$1" \)
Thanks Ben. This is just what I needed.