Page 1 of 1

$1 vs \1

Posted: Tue Oct 20, 2020 10:19 am
by ebulerdo
Good morning!

Can you help me understand the difference between $n and \n to refer to the content captured between (), please?

I have an XML file where every record is in a single line, so I search for

Code: Select all

</(.+?)><
and replace it with

Code: Select all

</$1>\r\n<
to move every tag to a new line. It works fine.

Now I realize that some fields in the same file are empty (ex. <MM:section></MM:section>) and want to remove them. So using the same logic as above I search for

Code: Select all

<(.+?)></$1>\r\n
and replace it with nothing. But it doesn't work.

After some testing and researching I realize it does work if I replace $1 with \1. So the issue is resolved. But I don't understand why.

Why did $1 work in the first case but not in the second one? Thank you!

Re: $1 vs \1

Posted: Tue Oct 20, 2020 10:25 am
by ebulerdo
Could it be that $1 is not working in the second example because I am using it in the same expression as the captured text? In the first case I used it in the Replace field.