Hey Jeff,

On Feb 27, 2014, at 15:34, outtacontext <[email protected]> wrote:
> Oliver, when I used yours and did a find, BBEdit didn't find anything. :-( 

At first blush it looks like Oliver didn't account for the possibility of 
variable whitespace.

> Christopher, yours worked. But I would you explain your comment:
> 
> Note: With freespacing on in the pattern all whitespace must be explicitly 
> defined.  (The pattern works as is.)  I also have case-sensitive turned OFF.

http://www.regular-expressions.info/freespacing.html

In short - with free-spacing ON you can insert space, tab, return/linefeed 
without affecting the regular expression pattern.

This allows you to use whitespace to break up your pattern to make it more 
readable, and it free-spacing also allows for in-line comments in the pattern.

Ordinarily a string like this:

"some-text
"

Will find "some-text<return/linefeed>".

The end-of-line character depends on what editor you're working in, and if you 
don't know the difference between \n (Unix), \r (Classic Mac), and \r\n 
(Windows) you can get into to some frustrating situations.

I meant that case-insensitive is turned OFF by the pattern rather than in the 
BBEdit find dialog.

> And, can you briefly explain the syntax? Oliver's is easy to understand. But 
> I don't get yours and I would like to so I know how to do this in the future.

Briefly?  :)

You'll need to study up on regular expressions if you want some real 
understanding[1].

Pattern:

(?xi) # Freespacing ON and case-sensitive OFF
^[[:blank:]]*<blockquote>[[:blank:]]*\r
^[[:blank:]]*<h3><a[[:blank:]]href="/exhibitions/online/roby/.+?\.cfm">.+?</a></h3>[[:blank:]]*\r
^[[:blank:]]*</blockquote>[[:blank:]]*\r?

Explanation:

(?xi)       == Pattern modifiers (p. 180 BBEdit Manual); x = free-spacing, i = 
case-insensitive.
            == In the case above these are switched ON
            == Note the in-line comment in the pattern: # Freespacing ON and 
case-sensitive OFF
^           == Beginning of line.
[[:blank:]] == Horizontal whitespace (space, non-breaking-space, tab).
*           == Zero or more instances of the character, group, or range that 
precedes it.
+           == One or more instances of the character, group, or range that 
precedes it.
?           == One or zero instances of the character, group, or range that 
precedes it.
.           == Any character.
\           == Escape character turning special regex characters like . into 
literal \. characters.
            == Or turning literal characters into special characters like \t 
tab.
\r          == Return character (synonymous with \n in BBEdit but not 
elsewhere).

That's about all I have time for.

--
Best Regards,
Chris


[1]:
----------------------------------------------------------------------
Some Information on Learning Regular Expressions
----------------------------------------------------------------------

Learning basic regular expressions is relatively easy.  Becoming really good 
with them takes dedication, a lot of practice, and some tutelage.

The BBEdit Manual devotes a whole chapter to regular expressions: Searching 
with Grep (currently chapter 8).  It's a reference rather than a tutorial, but 
it does explain at least briefly many of the fundamentals.

My cheat-sheet for BBEdit/TextWrangler is up on Gist: 
https://gist.github.com/ccstone/5385334.  BBEdit/TextWrangler uses PCRE (Perl 
Compatible Regular Expressions), so it's a pretty decent if not complete 
reference.

Regex neophytes are better off starting with a book specifically written for 
beginners.

I have these books (in addition to a couple of tomes on Perl):

"Sams Teach Yourself Regular Expressions in 10 Minutes" by Ben Forta
"Beginning Regular Expressions" by Andrew Watt
"Regular Expressions Cookbook"  by Jan Goyvaerts and Steven Levithan
"Mastering Regular Expressions" by Jeffrey Friedl (Advanced)

There's a decent little utility available on the App-Store called 'Patterns' 
that live-updates as you create your pattern. ($2.99)

http://itunes.apple.com/us/app/patterns-the-regex-app/id429449079?mt=12

I've found it very handy to have live feedback when building a complex pattern 
and wish I'd had something like that when I started learning regex more than 20 
years ago.

Extracting a good working knowledge of regular expressions from the Internet is 
a serious chore.  There are many flavors of regex out there, such as Perl/PCRE, 
Java, Javascript, Ruby, Python, TCL...  They're all similar, but the 
differences can be very confusing and frustrating.

Nevertheless there are many useful online resources.  Here are a few:

http://www.agillo.net/regex-primer-part-1/
http://www.agillo.net/regex-primer-part-2/
http://www.codeproject.com/KB/dotnet/regextutorial.aspx
http://www.regular-expressions.info/tutorial.html

----------------------------------------------------------------------

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" 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 [email protected].
To post to this group, send email to [email protected].

Reply via email to