Page 1 of 1

How to replace only part of a regular expression??

Posted: Fri Nov 01, 2013 1:08 am
by eike33
Hi all,

I'm cleaning text files that were scanned and digitally converted to txt files, and I'm attempting to search for commas in the files that accidentally became digitally converted to periods. For example:

The person. who was terribly exhausted, took a nap.

I want to replace the period after "person" to a comma, so I'm using (\. )[a-z] to find that specific instance. However, when I try to replace with a comma, the entire expression replaces and so the sentence becomes "The person, ho was terribly exhausted, took a nap." As you can see, in searching for [a-z], that first letter of the next word also is replaced.

Is there a way to get around this so that I can search only for instances where a lowercase letter follows a period, but retain the full word that follows the period and space? Thank you!!!

Re: How to replace only part of a regular expression??

Posted: Fri Nov 01, 2013 10:04 am
by DigitalVolcano
Try this:

RegEx:

Code: Select all

\. ([a-z])
Replace:

Code: Select all

, $1
The brackets create a 'capturing group', the contents of which can be deployed in the replacement using the $1 expression (ie 1st capturing group).
Ensure that the 'Case Sensitive' option is on too, so it doesn't capture legitimate full stops.

Hope this helps!

Re: How to replace only part of a regular expression??

Posted: Fri Nov 01, 2013 5:41 pm
by eike33
I think this works, thank you!