regexp question
Hi, I'm a bit stuck with regexp:
In an incoming textfile, I trying to know what string of character follows the last instance of a special word/symbol
The problem is that I manage to get the string which follows the first occurence.. but how to get what follows the last one?
ex:
in a text like:
bla e bla e bla a blo e blip a bloc
I whant to extract what follows the last "e" (which is "blip")
thanks for your help...
The third solution using a positive look behind is not that great because you need to filter to get only the last one. But I guess the first one is straightforward.
.*e\s(\S++)
where
. any character
* which appear from 0 to many times (greedy quantifier)
e a normal 'e' character
\s a space character
( ) memorize everything between those paranthesis (backreference)
\S non spaces characters
++ which appear at least once (lazy quantifier, try to get the smallest amount of \S
HI,
thanks for your explanation, it suits me very well for the moment,
but in the future, I will have to parse a string like that
"e blip e blop e blup e blup e blop..... "
and I will have to get what follows the first, the 2nd or the third or the nth "e"
how to parse it with regexp?
can I specify in my expression the number of "e" that have to be ignored before firing out the desired string?
thx again.
You could find all instances of a word preceded by e and then group them together and select the one you want using the [zl] family of objects. Here's an example.
lh
HI...
quick answer!
I wondered if it was possible to do all the parsing in the expression... visibly not..
is there a great link where to (easyly) learn regular expressions (excluding http://www.regular-expressions.info/), a book like "regexp for dummies" may exist?
thx
bye.
Here's a tutorial I've started (but not finished) on using [regexp] in max. It might help you out a bit.
lh
Three excellent sources of tutorial on Regular expressions:
The first section of
Programming Perl by Larry Wall., a chapter called Regular Expressions
# ISBN-10: 0596000278
# ISBN-13: 978-0596000271
the RegExp syntax is perhaps nowhere better explained
And
Mastering Regular Expressions - Jeffrey Friedl
# ISBN-10: 0596528124
# ISBN-13: 978-0596528126
The RegExp syntax and engine clearly explained in a language independent way...with examples in most language's implementation of reg exp, so you can apply what you learn.
go here to become *skillful* at building useful matching patterns.
Also , once you learn it, you will want a reference for quick..errr...reference(?) TRY
Regular Expression Pocket Reference: Regular Expressions for Perl, Ruby, PHP, Python, C, Java and .NET (Pocket Reference )
by Tony Stubblebine
# ISBN-10: 0596514271
# ISBN-13: 978-0596514273
RegExp looks so difficult, but with a little patience, it becomes quite logical and clear...
like most programming!
g'luck,
char lieb
I found chapter 8 of the TextWrangler user manual very helpful, that was pointed out to me by someone else on this list in an earlier regexp discussion (can't remember who but thanks!). The mozilla developer centre page is also worth a look.
lh
I concur. TextWrangler documentation is really great when you don't fully remember some syntax. Mastering regular expressions is there for truly nerds who wants to know how the regexp engines works (or why the same expression doesn't behave the same way depending on the regexp engine used), probably the funniest nerdiest book I've ever read.
great...
lots of sources to explore..
thanks everybody.