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 03-09-2012, 11:32 AM   #1
Andrew B.
Staff
 
Andrew B.'s Avatar
 
Join Date: Jan 2005
Location: Los Angeles, California
Posts: 3,501
Default Another Regex Question

I can't seem to get this right. I want to identify a series that begins with two words and ends with two words. So it would be something like:

"The Beginning" * "And End"

With the asterisk being anything in between.

   
__________________
fallberry.com
Andrew B. is offline   Reply With Quote
Old 03-09-2012, 08:44 PM   #2
Howard Allen
Member
 
Howard Allen's Avatar
 
Join Date: Oct 2007
Location: Calgary, Alberta, Canada
Posts: 824
Default

There's more than one way of doing this, depending on what sort of characters the "anything in between" consists of, and whether you want to include carriage returns, line feeds, etc.

But adhering strictly to the conditions you gave, this string should do the job:

[A-Za-z]+ [A-Za-z]+[\s\S]+?[A-Za-z]+ [A-Za-z]+

The [A-Za-z]+ finds one or more alphabetic characters. Note this is followed by a space, then [A-Za-z]+ to find the second word. [\s\S]+? finds any "whitespace" or "non-whitespace" character (one or more, including carriage returns). The ? is a "non-greedy" operator to prevent the GREP/regex from selecting everything up to the end of the document (otherwise your last two words would be included as "whitespace" or "non-whitespace" characters). The rest of the string finds the last two words.

This flavour of GREP works in TextWrangler & BBEdit (Mac). Hopefully it'll work in whatever you're using, otherwise find the equivalent string operators.

In the following example:

413a, 115, 6 two words/.,376 (115, 205a, 11).135, 2212113.44
313, 14!two words, 272, 116, (14)two more112, 34(5)
11714, (14a)two more16443.987, 114.

It will find:

"two words/.,376 (115, 205a, 11).135, 2212113.44
313, 14!two words"

and

"two more112, 34(5)
11714, (14a)two more"

   
__________________
Howard

OSX 10.10.5
Howard Allen is offline   Reply With Quote
Old 03-09-2012, 10:04 PM   #3
Andrew B.
Staff
 
Andrew B.'s Avatar
 
Join Date: Jan 2005
Location: Los Angeles, California
Posts: 3,501
Default

Thanks, Howard. The first one worked. But I used my specific beginning two words and ending two words. Good to know how to make it any words, though.

The program is Text Aloud, btw. I use regex in its pronunciation dictionary to tell it how to speak certain types of text that come up again and again.

   
__________________
fallberry.com
Andrew B. 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 needed to close <p> tags. dacoyle Web Design 5 10-26-2011 08:09 PM
Regex Question Andrew B. General Publishing Topics 2 09-20-2011 07:46 PM
Need Regex help Andrew B. General Publishing Topics 7 05-08-2011 08:56 AM
RegEx help dacoyle Web Site Building & Maintenance 6 04-14-2009 07:48 AM
Perhaps I shouldn't ask this question Franca On Language & Literature 12 04-18-2006 11:29 AM


All times are GMT -8. The time now is 10:22 PM.


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