grep lower case upper case sequence manipulation

599 views
Skip to first unread message

Rob Russell

unread,
Nov 23, 2016, 9:25:22 AM11/23/16
to BBEdit Talk
Hi grep experts,

I'm trying to convert sequences of lower case character upper case character pattern to lower case <space> upper case.

Like photographing children and animals, grep can make one look silly.

specifically, I have a file full of entries like this:

"273","BoysSummerSchool2013"
"405","Bridge Clubs"
"30","ChristmasCard2008"
"144","ChristmasCard2009"


which I would like to convert to

"273","Boys Summer School 2013"
"405","Bridge Clubs"
"30","Christmas Card 2008"
"144","Christmas Card 2009"

(brownie points for lower-digit sequence, I didn't get that far).

I expected the grep find and replace of 

([a-z])([A-Z])

to 

\1 \2

however, this is putting the spaces after the upper case chars. Hmmmm.

Other variants make me look equally stupid.

BBEdit 11.6.2

Any assistance appreciated.

Thanks

Rob

Fletcher Sandbeck

unread,
Nov 23, 2016, 10:17:25 AM11/23/16
to bbe...@googlegroups.com
The pattern should work fine, but make sure that you check the "Case Sensitive" checkbox in the Find/Replace dialog box. By default BBEdit ignores case sensitivity so [a-z] will match letters of any case. You can add [0-9] to the second part of your pattern to add a space before the years.

([a-z])[A-Z0-9])

Hope this helps,

[fletcher]

--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.

Bruce Van Allen

unread,
Nov 23, 2016, 10:54:06 AM11/23/16
to bbe...@googlegroups.com
Hey Rob,

Your Search/Replace patterns work over here - BUT, make sure in
the Find dialog that you have "Case sensitive" checked.

Also, here's a mod of your pattern that will also put the spaces
before the years, by accepting a number (\d) as an alternative
to the upper case letter:

Find:

([a-z])([A-Z]|\d)

Replace:

\1 \2

HTH
--

- Bruce

_bruce__van_allen__santa_cruz__ca_

Christopher Stone

unread,
Nov 24, 2016, 11:09:30 AM11/24/16
to BBEdit-Talk
On Nov 22, 2016, at 23:26, Rob Russell <sum...@gmail.com> wrote:
Like photographing children and animals, grep can make one look silly.


Hey Rob,

I reckon any given miscalculation can make someone look silly – the trick is to not mind too much.

😎

This pattern switches on case-sensitivity and uses Positive Look-Behind and Positive Look-Ahead assertions to discover adjacent lower-case-letters and (upper-case-letters or numbers):

Find:

(?-i)(?<=[a-z])(?=[A-Z0-9])

Replace with a space character.

As the Perl people say TMTOWTDI.

Like many things this level of regex is dead-simple once you know how, but learning how takes a good deal of study, practice, and some mentoring.

I've been using regular expression extensively for over 20 years, and I still wouldn't call myself an expert.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages