View Single Post
Old 02-24-2018, 02:14 PM   #8
sjfan
Addict
sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.sjfan ought to be getting tired of karma fortunes by now.
 
Posts: 281
Karma: 7724454
Join Date: Sep 2017
Location: Bethesda, MD, USA
Device: Kobo Aura H20, Kobo Clara HD
Quote:
Originally Posted by nopi1001 View Post
:
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
sjfan is offline   Reply With Quote