Quote:
Originally Posted by nopi1001
:
Another question did come up though. In the replace field you said to put a \1. This worked beautifully but if you could explain why/what exactly this (expression?) is doing, I would greatly appreciate it as this was one of the things that was tripping me up (being able to dynamically copy & paste part of something found with desired changes).
|
In the expression, parenthesis are used to create “capturing subpatterns”. These are automatically numbered, starting with “1”. In the replacement field, backslash followed by a number is replaced with the contents of the corresponding capturing subpattern.
Consider the sentence “I like Saturday and Sunday, but Samuel prefers sandwiches.”
Search for: .*(Sat[^ ]*).*\(san.*\)[.]
Replace with: \2 was last, \1 was first
Results in: “sandwiches was last, Saturday was first”
That's a relatively simple case, there are a lot of other possiblities.
http://www.pcre.org/current/doc/html...ern.html#SEC19
http://www.pcre.org/current/doc/html...ern.html#SEC14