Forums > MaxMSP

regexp question

May 28 2009 | 3:57 pm

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?
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…

May 28 2009 | 4:51 pm

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.



.     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

— Pasted Max Patch, click to expand. —
May 31 2009 | 11:17 pm

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.

May 31 2009 | 11:48 pm

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.


— Pasted Max Patch, click to expand. —
Jun 01 2009 | 12:14 am

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, a book like "regexp for dummies" may exist?

Jun 01 2009 | 1:29 am

Here’s a tutorial I’ve started (but not finished) on using [regexp] in max. It might help you out a bit.


Jun 01 2009 | 1:54 pm

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

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!

char lieb

Jun 01 2009 | 4:30 pm

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.


Jun 01 2009 | 4:38 pm

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.

Jun 03 2009 | 1:21 am

lots of sources to explore..
thanks everybody.

Viewing 10 posts - 1 through 10 (of 10 total)

Forums > MaxMSP