New to grep in Textwrangler find and replace

961 views
Skip to first unread message

Stuart Noggle

unread,
Sep 30, 2017, 2:36:20 PM9/30/17
to TextWrangler Talk
I'm new to grep in TextWranger find and replace. I'm trying to figure out how to use it. For example, I want to capitalize the first letter of successful, unsuccessful, and successful the the following text.

Mission: successful
Last mission: unsuccessful To be completed
Next mission: successful upon capture of target

------------------------------------------------------------
Find field: (:\s*\w)

Replace field: \u

Result: 
Missionuccessful
Last Missionnsuccessful To be completed
Next Missionuccessful upon capture of target
------------------------------------------------------------


I've tried several different variations, but I can get it. I'm doing well with building matches, but I can't seem to figure out the replace expressions. There are many times where I have to capitalize specific letters, but the Change Case tools sometimes capitalizes word that don't need it. I want to use grep to target specific groups of words. Thanks for your help!

Patrick Woolsey

unread,
Sep 30, 2017, 4:16:58 PM9/30/17
to textwr...@googlegroups.com
Since the purpose of the modifier \u is to 'make the next
character uppercase', you must place this modifier immediately
before the character you want to transform.

So, for example, if you use this search pattern:

Find: (:\s*)(\w)

to match a literal colon : followed by zero or more _whitespace
characters \s* which are all contained within a _subpattern_ (
) and followed by another subpattern ( ) containing a word
character \w you can then write this replace pattern:

Replace: \1\u\2

which inserts the contents of the first subpattern \1 followed
by the modifier \u to capitalize the next character which is the
word character contained in the second subpattern \2.

NB: If you don't include the subpattern specifiers in your
replace pattern
then TextWrangler will replace whatever text they matched
with nothing,
which is useful if you want to delete that text, but not
so much if
you're trying to transform it. :-)

So, please give this a try and I think you may find it useful.

[PS: For complete details about using TextWrangler's grep
capabilities, including examples, please see Chapter 8 of the
included PDF manual, which you can access at any time via Help
-> User Manual.]

Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>

Jean-Christophe Helary

unread,
Sep 30, 2017, 8:35:13 PM9/30/17
to textwr...@googlegroups.com

> On Oct 1, 2017, at 5:16, Patrick Woolsey <pwoo...@barebones.com> wrote:
>
> [PS: For complete details about using TextWrangler's grep capabilities, including examples, please see Chapter 8 of the included PDF manual, which you can access at any time via Help -> User Manual.]

FWIW, that chapter, which is roughly the same as what was in BBEdit Lite back in 95-96 when I started using it, is so well written that even now I go back to it when I need to check *anything* about regular expressions.

Of course, different engines have different syntax, but it still can be used as a general regex reference and it really is what got me started in "computing".

Jean-Christophe
Reply all
Reply to author
Forward
0 new messages