Forum Made Regexp Tutorial

Dec 10, 2008 at 1:00pm

Forum Made Regexp Tutorial

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!

#41280
Dec 10, 2008 at 1:12pm

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

#146851
Dec 10, 2008 at 1:21pm

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.

#146852
Dec 10, 2008 at 1:42pm

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

#146853
Dec 10, 2008 at 2:19pm

#146854
Dec 10, 2008 at 2:39pm

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.

#146855
Dec 10, 2008 at 6:14pm

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)

#146856
Dec 10, 2008 at 7:19pm

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

#146857
Dec 10, 2008 at 9:20pm

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
>
>
—————————————————-

#146858
Dec 10, 2008 at 10:11pm

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

#146859
Dec 12, 2008 at 1:49am

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

Yo ;-)

#146860
Dec 12, 2008 at 1:55am

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

#146861
Dec 12, 2008 at 5:23pm

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!

#146862
Dec 12, 2008 at 6:47pm

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

#146863
Mar 26, 2009 at 11:38pm

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.

#146864
Mar 27, 2009 at 12:59am

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

#146865
Mar 27, 2009 at 5:30am

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

#146866
Mar 27, 2009 at 11:12am

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. –
#146867
Mar 27, 2009 at 5:31pm

thanks, I will see later my dump problem..

#146868
Mar 27, 2009 at 10:31pm
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.

#146869
Apr 10, 2009 at 1:28pm

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

#146870
Apr 10, 2009 at 4:47pm

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

#146871
Apr 11, 2009 at 6:17am

great, thanks again.

#146872
Jun 5, 2009 at 8:54am

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. –
#146873
Jun 5, 2009 at 11:31am

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

#146874
Jun 5, 2009 at 3:30pm

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.

#146875
Jun 5, 2009 at 5:29pm

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

#146876
Jun 5, 2009 at 6:20pm

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.

#146877
Jun 5, 2009 at 9:36pm

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

#146878
Jun 6, 2009 at 3:26am

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)

#146879

You must be logged in to reply to this topic.