DTP


 
Lively discussions on the graphic arts and publishing — in print or on the web


Go Back   Desktop Publishing Forum > General Discussions > General Publishing Topics

Reply
 
Thread Tools Display Modes
Old 05-07-2011, 11:36 AM   #1
Andrew B.
Staff
 
Andrew B.'s Avatar
 
Join Date: Jan 2005
Location: Los Angeles, California
Posts: 3,501
Default Need Regex help

Any of you happen to be good a regular expressions? Or know a forum where I can ask. Here's what I want to search for

1. A open and close parenthesis plus all that is between them, but only if one of the characters inside is a colon.

2. A number (meaning: a series of one or more numeric characters) followed by a colon. IOW, it would treat 1: and 12: and 123: the same.

   
__________________
fallberry.com
Andrew B. is offline   Reply With Quote
Old 05-07-2011, 12:51 PM   #2
ktinkel
Founding Sysop
 
ktinkel's Avatar
 
Join Date: Oct 2004
Location: In Connecticut, on the Housatonic River near its mouth at Long Island Sound.
Posts: 11,189
Default

Even thinking about thinking about regular expressions makes me dizzy, but here are a couple of web resources that may help you figure it out:

Regular-Expressions.info Sort of a cookbook format.

grep basics

   
__________________
[SIZE=2][COLOR=LemonChiffon]::[/COLOR][/SIZE]
[SIGPIC][/SIGPIC]
ktinkel is offline   Reply With Quote
Old 05-07-2011, 04:44 PM   #3
annc
Sysop
 
annc's Avatar
 
Join Date: Oct 2004
Location: Subtropical Queensland, Australia, between the mountains and the Coral Sea
Posts: 4,434
Default

I love GREP!

Try these:

For your no. 1 (I assume you are using standard round parentheses. If you are using square parentheses or curly braces, just replace these with the ones you want to search on.)
\(.*\:.*\)

For your no. 2
[0-9]+\:

Note that you have to do this in a text editor that recognises standard regular expressions. The Microsoft versions vary somewhat. Make sure you have the checkbox for regular expressions ticked or you will get very different results.

Do you need replacement strings as well? The find string changes if you do.

I tested both of these in BBEdit and they worked.

   
__________________
annc is offline   Reply With Quote
Old 05-07-2011, 07:20 PM   #4
Howard Allen
Member
 
Howard Allen's Avatar
 
Join Date: Oct 2007
Location: Calgary, Alberta, Canada
Posts: 824
Default

Ann (and especially Andrew)!

Andrew's first example was a bit of a challenge--I like GREP puzzles, too! Unfortunately, Ann's first GREP string doesn't work in all cases. I tried it in TextWrangler on several different combinations. Since the .* wildcard combo searches for zero or more instances of any character except a carriage return, it will find any character between the first left parenthesis and the next carriage return; it won't stop when it sees the next right parenthesis, so it could select several sets of parentheses in a line, and everything else up to the carriage return, even if those other sets of parentheses don't contain a colon. For example, try it on this line:

If you find anyone in the office (Fred, Jane or Bob) give them (as soon as possible) the numbers (12345:).


Here's one that should work:

\([^)]*\:+[^)]*\)

This one searches for a left parenthesis, plus zero or more instances of any character EXCEPT a right parenthesis, followed by one or more instances of a colon, followed by zero or more instances of any character EXCEPT a right parenthesis, followed by a right parenthesis.

Andrew's second problem is much easier; Ann's suggested string will do the job. Here's another one that will work:

\d+\:

This one just looks for one or more instances of any digit, followed by a colon.

Cheers,

   
__________________
Howard

OSX 10.10.5

Last edited by Andrew B.; 05-07-2011 at 07:51 PM.
Howard Allen is offline   Reply With Quote
Old 05-07-2011, 07:46 PM   #5
Andrew B.
Staff
 
Andrew B.'s Avatar
 
Join Date: Jan 2005
Location: Los Angeles, California
Posts: 3,501
Default

Thanks, Howard. I wish I had asked sooner.

FWIW, vBulletin offers an option under the text entry window to disable smiles. I already fixed it.

   
__________________
fallberry.com
Andrew B. is offline   Reply With Quote
Old 05-07-2011, 08:14 PM   #6
Andrew B.
Staff
 
Andrew B.'s Avatar
 
Join Date: Jan 2005
Location: Los Angeles, California
Posts: 3,501
Default

Me again. I'm curious. Why do I have to specify the possibility of more than one colon.

   
__________________
fallberry.com
Andrew B. is offline   Reply With Quote
Old 05-07-2011, 10:28 PM   #7
annc
Sysop
 
annc's Avatar
 
Join Date: Oct 2004
Location: Subtropical Queensland, Australia, between the mountains and the Coral Sea
Posts: 4,434
Default

Thanks, Howard.

   
__________________
annc is offline   Reply With Quote
Old 05-08-2011, 08:56 AM   #8
Howard Allen
Member
 
Howard Allen's Avatar
 
Join Date: Oct 2007
Location: Calgary, Alberta, Canada
Posts: 824
Default

Quote:
Originally Posted by Andrew B. View Post
Me again. I'm curious. Why do I have to specify the possibility of more than one colon.
You don't. Just the way you stated your problem: "A open and close parenthesis plus all that is between them, but only if one of the characters inside is a colon." I wasn't sure if you meant only one or at least one of the characters is a colon. The expression I gave you covers either circumstance. If you want to find instances with only one colon, then just omit the + sign.

Cheers,

   
__________________
Howard

OSX 10.10.5
Howard Allen is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RegEx help dacoyle Web Site Building & Maintenance 6 04-14-2009 07:48 AM


All times are GMT -8. The time now is 07:15 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Contents copyright 2004–2014 Desktop Publishing Forum and its members.