Reply To: Grep simple query

#60798

Only for today I'll offer you not one but two ways.

Search for

(d.)[a single space]+

Replace with

$1t

The parentheses mark “Found group #1”, and you can insert this back again in the Replace expression with “$1”. This feature is particularly useful when you need to swap two items around (in Replace you can use something like “$2 $1”) or want to repeat something (simply write “$1 $1 $1 $1” to get five copies of whatever you found).

There is a more advanced way, though: you can search for one or more spaces and then use a Positive Lookbehind to ensure these are preceded by a digit plus a period. The advantage is the expression doesn't “touch” the digits, only (I believe it is an advantage, but for reasons more spiritual rather than practical. It may also run a bit faster.).

Search for

(?<=d.)[a single space]+

Replace with

t

This article was last modified on October 18, 2011

Comments (0)

Loading comments...