Forums > MaxMSP

Forum Made Regexp Tutorial


Dec 10 2008 | 1:00 pm

The "regexp is no fun!" thread posted by Stefan Tiedje is a very useful thread an my thinking was that it would be very useful to combine this information into a max patch.

I’m still very much learning regexps myself so it would be difficult to include al the information with clear descriptions myself. Therefore I propose we put together, collectively, a max patch that could be included with max or placed in the share section or distributed in some way to people who are struggling with the regexp object.

I already threw together some examples (it’s about lunchtime if that explains my examples!) which I hope are easy to understand. There’s very little there so far but I will add some more.

If you can help then please contribute something to the patch and repost it on here! This way we can also check that nobody has written anything daft or that doesn’t make sense which I certainly am prone to doing.

If you contribute something feel free to add your name to the contributors subpatch.

I hope you agree with me that this is a good idea!

Dec 10 2008 | 1:12 pm

Excellent idea, perhaps in your examples you should include some [sprintf]s to set the "re" and "substitute" attributes.

I have some specific tools that utilise [regexp] which I could include but it looks to me that you want to start this tutorial from the bottom up, so explaining some of the regex characters in detail might be better first. Let me see what I can come up with.

lh

Dec 10 2008 | 1:21 pm

Great to have you on board. I think an explanation from the bottom up is a good idea but some specific examples with a bit of documentation could be useful. I am working on modifying something I have been using for a project into a tutorial which I will add later.

Looking forward to seeing what you come up with.

Dec 10 2008 | 1:42 pm

Well today is my day off work so I’d be happy to write a few tutorials. If more people start helping out, which I’m sure they will, then you might have to go all editorial on us and format things for a bit of continuity so that people can make sense of each contributors patching style.

It might be an idea to do this in Max4 so a wider group of people will be able to benefit from it, what do you think?

Here’s some examples on the forum. The first is parsing a webpage to find an IP address and the second is filtering items from the end of a list.

http://tinyurl.com/5p27pf
http://tinyurl.com/56aevd

lh

Dec 10 2008 | 2:19 pm

Dec 10 2008 | 2:39 pm

Great to have you onboard too Stefan! Looking forward to seeing some examples.

I added your ip address abstraction Luke (very useful) and wrote a quick explanation. I haven’t done the other yet, I have to do some other work first. Perhaps you could write a short explanation when you get chance?

P.s. That CT collective is brilliant. Don’t give me ideas! Haha.

Dec 10 2008 | 6:14 pm

here’s the patch again, with a bunch of path and extension examples added (i posted them on the pvs. thread, so I thought I’d clean them up a bit integrate them into this master file)

Dec 10 2008 | 7:19 pm

Quote: thereishopeforus@hotmail.com wrote on Wed, 10 December 2008 14:42
—————————————————-
> It might be an idea to do this in Max4 so a wider group of
> people will be able to benefit from it, what do you think?
—————————————————-

Oh yes, please!
I’m still working with 4.6.3.
TIA

Dec 10 2008 | 9:20 pm

I missed that. Yes I think a Max4 version would be a good idea. I have Max4 installed on this machine but almost al my patches are in Max5 now.

If people want to contribute in Max4 now I’ll add them to both versions.

Quote: Philippe Gruchet wrote on Wed, 10 December 2008 20:19
—————————————————-
> Quote: thereishopeforus@hotmail.com wrote on Wed, 10 December 2008 14:42
> —————————————————-
> > It might be an idea to do this in Max4 so a wider group of
> > people will be able to benefit from it, what do you think?
> —————————————————-
>
> Oh yes, please!
> I’m still working with 4.6.3.
> TIA
>
>
—————————————————-

Dec 10 2008 | 10:11 pm

Just a bit of tidying/editorial. I’ll get on with a Max4 version when I have time.

Dec 12 2008 | 1:49 am

Quote: fairesigneaumachiniste wrote on Wed, 10 December 2008 23:11
—————————————————-
> I’ll get on with a Max4 version when I have time.

Yo ;-)

Dec 12 2008 | 1:55 am

Philippe, seeing as you can download the maxpat file rather than just copying the compressed text version you should look into the supercollider 5to4 converter written by Fredrik Olofsson. You can find it here:

http://www.fredrikolofsson.com/pages/code-sc.html

lh

Dec 12 2008 | 5:23 pm

Quote: thereishopeforus@hotmail.com wrote on Fri, 12 December 2008 02:55
—————————————————-
> Philippe, seeing as you can download the maxpat file rather than just copying the compressed text version you should look into the supercollider 5to4 converter written by Fredrik Olofsson. You can find it here:
>
> http://www.fredrikolofsson.com/pages/code-sc.html
>
> lh
—————————————————-

Hmm… seems to convert Max5 patcher into SC only with "MaxPat.sc".
Is there’s something I do not understand?
Thanks!

Dec 12 2008 | 6:47 pm

Philippe Gruchet wrote:
> Hmm… seems to convert Max5 patcher into SC only with "MaxPat.sc".
> Is there’s something I do not understand?
> Thanks!
>

Hi.

*.sc is a SC source file.

Just open MaxPat.html in SuperCollider (which is the help file), find
the line "GUI.dialog.getPaths" and double-click just above this line (it
should select the whole block of text), close to the opened parenthesis.
Then press "enter" (*not* return), and let the magic happen ;)
Your converted file is in the same folder as the max5 one.

Ciao

Mar 26 2009 | 11:38 pm

hello,
learning regular expressions, I download a text file into a text object and in order to parse it with my my regexp, I needed to output all the lines at once, not one line after another.
Is there a way to output the textfile in one shot?
(line per line my parsing doen’t work)
each time I saw examples, the text to be parsed was in a message box and not in a text object…
thanks for your help.

Mar 27 2009 | 12:59 am

The "dump" message should do it.

For those that are interested I will be posting a fairly simple regexp tutorial patch online in about a week, I’m just working on a few example patches now. I’ve been meaning to finish this for a while and have been sidetracked by learning how to use javascript among other things. I don’t profess to be an expert so when it’s up if you want to take a look and let me know if anything is amiss then please do.

lh

Mar 27 2009 | 5:30 am

thanks,

in fact sometimes the dump does not work,
here is an example:

— Pasted Max Patch, click to expand. —

I ‘m impatient to see your tutorial

Mar 27 2009 | 11:12 am

I can’t get the reuters web address you included to work but personally when using [jit.uldl] I find it easier to stick to jitter objects to do regex searches. It means you don’t have to download to and then read from your HD. Here’s an example.

lh

— Pasted Max Patch, click to expand. —
Mar 27 2009 | 5:31 pm

thanks, I will see later my dump problem..

Mar 27 2009 | 10:31 pm
fairesigneaumachiniste wrote on Wed, 10 December 2008 16:11
Just a bit of tidying/editorial. I’ll get on with a Max4 version when I have time.

Great patch—very handy! I especially like the IP one since it doesn’t need java/mxj installed to do the work. This way people running a networking-based patch (like a chat room or something) don’t have to find their IP and set it manually.

Apr 10 2009 | 1:28 pm

HI,
still experimenting with regexp, I would need clues for deleting (or detecting for the moment) the lines which are repeated in a textfile.
thanks for any help

Apr 10 2009 | 4:47 pm

I’ve been working on a "regexp in max" tutorial for a little while, it’s not complete but here is what I have to share so far. The patch is in max5 JSON format so it should be possible to use the supercollider converter to view it in max4. If anyone else wants to chime in with some corrections/examples/questions/pointers then feel free.

lh

http://www.thelightningbolts.com/luke/regexes.html

Apr 11 2009 | 6:17 am

great, thanks again.

Jun 05 2009 | 8:54 am

I keep on training with regexp (or jit.str.regexpr)
those days, I try to parse html code in order to get news titles in plain text.

I tried this but doesn’t work
there may be a dedicated tool for html parsing?

— Pasted Max Patch, click to expand. —
Jun 05 2009 | 11:31 am

Have a look at [detox] by jasch. It parses xml style tags and might be useful to you. Otherwise, here’s an expression that works:

[regexp ]*>(.*?)]

Be careful with your messages though, if they include reserved characters like ,commas, "quotes" and ;semicolons; you will probably need to escape them.

lh

Jun 05 2009 | 3:30 pm

thanks.
whatever I do i allways get errors:
"us" and "rhetoric" (that are preceded by semicolons in my message) get "no such object" in the max windows
Moreover, as soon as I try to delete reserved character I get the same errors.. arggh.

Jun 05 2009 | 5:29 pm

That’s because the ;semicolon; is used to send a message to a [receive] object (or max itself) and if you don’t have [receive] objects called "us" and "rhetoric" it can’t do this. Either remove the semicolons or try escaping them like this ; then see how you get on.

lh

Jun 05 2009 | 6:20 pm

when semicolons are manualy escaped , no errors but nothing goes out of my regexp.

detox works but fires out the tag content.
is this syntax right to substitute the tags before parsing the whole message?
[regexp
@substitute %0] it seems to be lazy but how to make it greedy? if i use a + it will only concern the previous character?
[regexp
+ @substitute %0] i want to link those 3 characters: ""

sorry for beeing so dumb about regexp.

Jun 05 2009 | 9:36 pm

To group character without storing as a match you can use brackets as shown below, it’s called a non-capturing reference. If you’re still having problems then post your re-worked patch.

(?:)

lh

Jun 06 2009 | 3:26 am

Hi.
here is my patch,
thanks to your explantions I managed to get what I desired..
but one problem persists when html code contains an ‘apostrophe’

— Pasted Max Patch, click to expand. —

thanks
piet

edit
PS: same problem with quotation mark (" in html)

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

Forums > MaxMSP