How to replace only part of a regular expression??

Tool for Search and Replace across multiple files.
Post Reply
eike33
Posts: 2
Joined: Fri Nov 01, 2013 1:01 am

How to replace only part of a regular expression??

Post 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!!!
User avatar
DigitalVolcano
Site Admin
Posts: 1731
Joined: Thu Jun 09, 2011 10:04 am

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

Post 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!
eike33
Posts: 2
Joined: Fri Nov 01, 2013 1:01 am

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

Post by eike33 »

I think this works, thank you!
Post Reply