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…
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
----------begin_max5_patcher---------- 673.3ocyW0saaCBF8ZmmBDW0tlgL+al1zzdF1kqUSNIzTO4XGESUyZUe22G3 zzjnDGWoVlijI3O.y46v4.hmFkfmTu11fQeA8KTRxSiRRBg7AR17dBdQ95ok 4MgtgqrOTO4O3wsM4rqcgvOVhVYm+R3k4to2UTM+2qrScsecgTPzJMMiNFQM RhfyxLrwHQJIcLhAkna1L5aqqbMEOZ8CjxflaCWc+hhpRqKfC1qAqu2cXz1P t+tz1N4X7X3Y6DTLKfYHO9LUh2YVqxWDFA9GqJxKw9FddzHew3dROKrMM4ys cQDZMQoDROQvDPcshSk.oj4SU3u2ElfdRlX6Ge4Jaisxk6JpqNE93bOlR2Tb TBT79RfmPe4PSPM8UdwLDdlQ.jZK9eypK5aScMIuZ9oUX7nPPf6ytdI5Z7Ee +qeyht7hqgeOb0UWdMtSwHmvMhrTEPaJFgBlRtFpykuiDmrSa4tOGi.Mw1gx 3FhPpTTyvzgtG9NuCUGW8G4SVT+DeLMkjo0JomaUThTIDpLnNULXDeYenhus rWi00oKkH4RI0uibphHTFMCLobFQNDNvfSjYBpQ.nilRDPgj1sj7+vgtuxfC QGcpwiCtvbNyrHllYvJ6MxMA67OA6bGLbVJQBq7bwgd4gyAI733kmTlirnWK ygx5P8hksuL8L7nWoBpyLZq3LxZzcXLV+XrvPwkEUGdUhP94iuOM1Te+pouL wa1kEQ2BfY1FWQUvirSez60m6JlMyFZ9kjeQwrk0EUtMP.cyQWR6KhfLGkdF DksWe9nQDuGbjXvwQ7nxQxdfH+EV5DRSqKqW0NfT3lPLs+hDGqFcGGY7yC8v OM5i.gFWEBs2Rj34iL8vYGvc7fzAqJcfoz3hoywSlA29MQe6F3kmG8O.L.if VC -----------end_max5_patcher-----------
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?
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.
----------begin_max5_patcher---------- 533.3ocwUF0aaBCDG+Y3SgkeZaJIBaBCXusOGMYSFhKwUfMBLZYspe2m4HzP ZKHuTDMRXm6Lb9+8ymsex0AmnNwqwneftC437jqiC3p0gyYaGbA6TZNqFdMr j+GUxC3UcCo4mzf6xJgT26sjoSOJjY+thmp6BNgtci2JD46wsc9fA0aiGZ+4 u4dkTKYEbHZ+rRvx6ilroPHy4ZX9IWbpZz8d8FDjZwiPPHzM8tEGfnZz8ZRL t02yttsMqrMoaJR3U8BxLjnnoncjsSjwgPpRnAscAdyaFSmNiMeeuDIuEBTu 9YpKh5+Vx6DMFVEQ3DlLCi1eKn58qOdLGI0GQDKJQ1F11EdykHzaAXCoCYT5 zhl4FKYUplRKvx45H+OKrPhVNrnQIn7IXRDPgvH3rD5lfEbm0PhDNJQf8O2L UJ300rL9avRRNCwQWZYlVE7eQYmQpwJUoVCOr0oGUpovnAc9AATpotBXIMBJ xHQyU4EwdX5Od40bVZUwy3mJQ6v7cle0e4teg1+sutCOAlhgCjHddc6Cil2S xCrGQzo2AN74JjABEmKju9pdHYa8eMGqUMUo8gtuRGQdIeOvq0BISKTxgujQ dnKP4n3vAtb3syEhCkJyELmEwHqpVqIpMZJZY0z0S26qo16WVPM8poaDNEur ZxyVNQVt0tPa3z+Y8TLb4DgRgiN78ew5iJVeaDa3GXQ0X7r6+HIRF6J -----------end_max5_patcher-----------
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?
Here’s a tutorial I’ve started (but not finished) on using [regexp] in max. It might help you out a bit.
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!
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.
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.
lots of sources to explore..
Forums > MaxMSP