$1 vs \1
Posted: Tue Oct 20, 2020 10:19 am
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 and replace it with 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 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!
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
</(.+?)><
Code: Select all
</$1>\r\n<
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
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!