Examples: Replacing Text

These examples all use UNIX extended regular expression syntax.

1. Find any alphabetic word starting with an upper case letter:
[A-Z][a-z]+
and replace with the same word all in upper case:

\U&
2. Find a C language variable name starting with a lower case letter:
\<[a-z][ a-zA-Z0-9]*
and make the first letter upper case:

\u&
3. Find two numeric strings separated by one or more spaces:
\([0-9]+\) +\([0-9]+\)
and swap them around, using a tab to separate them:

\2\t\1
4. Find “paste”:
paste
and replace with the contents of the clipboard:

\p
5. To change:
X100000 to X100.000
Y100123 Y100.123
Z600 Z.600
Find: \([XYZ]\)\([0-9]*\)\([0-9][0-9][0-9]\)
Replace: \1\2.\3

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: