Forums > MaxMSP

Baffled!! Regexp inconsistencies. Why?

November 9, 2006 | 5:54 am

I have been needing to use regexp and the jit.str.regexp alot lately. There
is one inconsistency (at least) that I don’t understand. It has to do with
formatting the expressions with or without a @ Can somehelp here?

Example showing….

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 54 458 100 196617 WORKS Also;
#P window linecount 13;
#P comment 470 370 196 196617 Somewhat unrelated question for the example on
the WORKS side. Why is there always an output from unmatched outlet , even
though substrings and substitutions occur with long string in the example?
The short string that contains a single 0 shows a match occurs Removing the
- in the 0-9 seems to have no affect either , nor does moving the decimal
place after the 0-9.;
#B color 1;
#P window linecount 1;
#P newex 343 615 72 196617 print noMatch;
#B color 2;
#P message 181 519 150 196617 flava flav rocks plastic clocks;
#P message 99 519 78 196617 i want you to 0;
#P newex 258 615 82 196617 print substrings;
#P newex 179 615 70 196617 print backRef;
#P newex 80 615 93 196617 print substitutions;
#P newex 80 571 295 196617 regexp @re
[0]|[1]|[2]|[3]|[4]|[5]|[6]|[7]|[8]|[9] @substitute " ";
#P message 80 487 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P newex 352 305 48 196617 loadbang;
#P comment 467 34 100 196617 DOESN’T WORK;
#P comment 54 247 100 196617 WORKS;
#P newex 730 211 72 196617 print noMatch;
#B color 2;
#P message 568 94 150 196617 flava flav rocks plastic clocks;
#P message 486 94 78 196617 i want you to 0;
#P newex 645 211 82 196617 print substrings;
#P newex 566 211 70 196617 print backRef;
#P newex 467 211 93 196617 print substitutions;
#P newex 467 146 138 196617 regexp re \\d substitute " ";
#P message 467 62 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P message 233 333 71 196617 substitute " ";
#P message 178 333 40 196617 re \\d;
#P newex 342 408 72 196617 print noMatch;
#B color 2;
#P message 180 305 150 196617 flava flav rocks plastic clocks;
#P message 98 305 78 196617 i want you to 0;
#P newex 257 408 82 196617 print substrings;
#P newex 178 408 70 196617 print backRef;
#P newex 79 408 93 196617 print substitutions;
#P newex 79 357 66 196617 regexp;
#P message 79 273 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P newex 341 189 72 196617 print noMatch;
#B color 2;
#P message 179 83 150 196617 flava flav rocks plastic clocks;
#P message 97 83 78 196617 i want you to 0;
#P newex 256 189 82 196617 print substrings;
#P newex 177 189 70 196617 print backRef;
#P newex 78 189 93 196617 print substitutions;
#P newex 78 135 154 196617 regexp @re \\d @substitute " ";
#P message 78 51 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P comment 54 32 100 196617 WORKS;
#P connect 1 0 2 0;
#P connect 6 0 2 0;
#P connect 7 0 2 0;
#P connect 2 0 3 0;
#P connect 18 0 10 0;
#P connect 17 0 10 0;
#P connect 15 0 10 0;
#P connect 14 0 10 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 36 0 31 0;
#P connect 35 0 31 0;
#P connect 30 0 31 0;
#P connect 31 0 32 0;
#P connect 2 1 4 0;
#P connect 29 0 17 0;
#P connect 10 1 12 0;
#P connect 31 1 33 0;
#P connect 29 0 18 0;
#P connect 2 2 5 0;
#P connect 10 2 13 0;
#P connect 31 2 34 0;
#P connect 2 3 8 0;
#P connect 10 3 16 0;
#P connect 31 3 37 0;
#P connect 19 0 20 0;
#P connect 24 0 20 0;
#P connect 25 0 20 0;
#P connect 20 0 21 0;
#P connect 20 1 22 0;
#P connect 20 2 23 0;
#P connect 20 3 26 0;
#P window clipboard copycount 40;


November 9, 2006 | 9:29 am

On 9 nov. 06, at 06:54, Dave Leith wrote:

> I have been needing to use regexp and the jit.str.regexp alot
> lately. There is one inconsistency (at least) that I don’t
> understand. It has to do with formatting the expressions with or
> without a @ Can somehelp here?

Hi,
your problem have nothing to do with regexp, but it’s related to the
attributes. Attributes allow you to create an object with special
behavior (instead of sending the messages via a message box and a
loadbang…. or a loadmess). The syntax is the "@" sign followed by
the name of the attributes and its arguments as you did on the left
side of your patch. One cool thing about the attributes is that you
can see what are the currents "values" of them while ctrl+option
+click (alt+right click on windows) on the object.

About the "why is there a no match outlet", look at the patch bellow,
it removes the aiff extension on a "file" if it exists. If you can
get the no match, it’s easier to deal with, if the regurlar
expression failed.

HTH,
ej

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 635 501 26 196617 toto;
#P newex 635 475 62 196617 prepend set;
#P message 672 391 43 196617 titi.aiff;
#P message 635 392 26 196617 toto;
#P newex 635 425 202 196617 regexp @re ([^.]+)\\.aiff @substitute %1;
#P fasten 0 3 3 0 784 454;
#P connect 0 0 3 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P connect 3 0 4 0;
#P window clipboard copycount 5;


November 9, 2006 | 6:02 pm

Thanks Emmanuel

I still think there there are a few very strange things happening here. (I
was aware of the attributes as I work with Jitter.) I have modified your
patch to show these and hopefully clarified my patch to show also. Sorry for
being thick about this I have ‘big’ plans for using the nomatch output. I
hope you can help.

Thanks again

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 144 207 150 196617 flava flav rocks plastic clocks;
#P message 177 863 329 196617 i want you to 0;
#P newex 177 837 62 196617 prepend set;
#P message 146 816 75 196617 0;
#P newex 146 790 62 196617 prepend set;
#P message 113 769 75 196617 0;
#P newex 113 743 62 196617 prepend set;
#P message 81 723 75 196617 0;
#P newex 81 697 62 196617 prepend set;
#P message 135 477 329 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B
C D E F G H I J K L M N;
#P newex 135 451 62 196617 prepend set;
#P message 117 420 75 196617 0;
#P newex 117 394 62 196617 prepend set;
#P message 99 359 75 196617 titi.aiff;
#P newex 99 333 62 196617 prepend set;
#P message 81 301 319 196617 i want you to;
#P newex 81 272 62 196617 prepend set;
#P window linecount 2;
#P comment 677 95 190 196617 This message produces 1 matches but incorrectly
produces a "nomatch" output;
#P window linecount 3;
#P comment 676 153 190 196617 This message produces 1 matches and correctly
has no output at the "nomatch" output;
#P button 72 479 15 0;
#P button 739 277 15 0;
#P window linecount 1;
#P message 652 323 75 196617 getattributes;
#P newex 652 297 62 196617 prepend set;
#P message 612 100 62 196617 titi.aiff.aiff;
#P newex 754 317 32 196617 print;
#P message 444 169 47 196617 getstate;
#P newex 794 279 62 196617 prepend set;
#P window linecount 0;
#P message 794 317 50 196617;
#P window linecount 1;
#P message 503 170 69 196617 getattributes;
#P message 553 323 75 196617 titi.aiff;
#P newex 553 297 62 196617 prepend set;
#P message 619 155 43 196617 titi.aiff;
#P message 618 128 26 196617 toto;
#P newex 595 246 202 196617 regexp @re ([^.]+)\\.aiff @substitute %1;
#P window linecount 3;
#P comment 183 150 190 196617 This message produces 1 matches and correctly
has no output at the "nomatch" output;
#P window linecount 1;
#P newex 315 236 48 196617 loadbang;
#P comment 81 553 100 196617 DOESN’T WORK;
#P comment 56 38 100 196617 WORKS;
#P message 182 613 150 196617 flava flav rocks plastic clocks;
#P message 100 613 78 196617 i want you to 0;
#P newex 81 665 138 196617 regexp re \\d substitute " ";
#P message 81 581 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P message 235 238 71 196617 substitute " ";
#P message 180 238 40 196617 re \\d;
#P message 99 156 78 196617 i want you to 0;
#P newex 81 243 83 196617 regexp;
#P message 81 64 323 196617 O P Q R S T U V W X Y Z 0-9. Album Index. A B C
D E F G H I J K L M N;
#P window linecount 2;
#P comment 99 87 232 196617 This message produces 2 matches but incorrectly
produces a "nomatch" output;
#P window linecount 6;
#P comment 255 670 100 196617 This always produces no match even though the
RE is the same as the above example and listed in regexp help;
#P window linecount 1;
#P comment 11 302 100 196617 substitutions;
#P comment 55 361 100 196617 backRef;
#P comment 65 421 100 196617 substrings;
#P comment 89 480 100 196617 noMatch;
#P window linecount 2;
#P comment 446 137 100 196617 These produce incorrect results;
#P window linecount 1;
#P comment 305 208 100 196617 OK;
#P connect 54 0 9 0;
#P connect 21 4 30 0;
#P connect 21 4 28 0;
#P connect 21 3 32 0;
#P connect 21 3 34 0;
#P connect 14 3 52 0;
#P connect 52 0 53 0;
#P connect 14 2 50 0;
#P connect 50 0 51 0;
#P connect 14 1 48 0;
#P connect 48 0 49 0;
#P connect 14 0 46 0;
#P connect 46 0 47 0;
#P connect 9 3 35 0;
#P connect 9 3 44 0;
#P connect 9 2 42 0;
#P connect 9 1 40 0;
#P connect 9 0 38 0;
#P connect 44 0 45 0;
#P connect 42 0 43 0;
#P connect 40 0 41 0;
#P connect 38 0 39 0;
#P connect 21 0 24 0;
#P connect 23 0 21 0;
#P connect 22 0 21 0;
#P connect 24 0 25 0;
#P connect 26 0 21 0;
#P connect 28 0 27 0;
#P connect 29 0 21 0;
#P connect 31 0 21 0;
#P connect 32 0 33 0;
#P connect 19 0 11 0;
#P connect 19 0 12 0;
#P connect 16 0 14 0;
#P connect 15 0 14 0;
#P connect 13 0 14 0;
#P connect 8 0 9 0;
#P connect 10 0 9 0;
#P connect 11 0 9 0;
#P connect 12 0 9 0;
#P window clipboard copycount 55;

On 11/9/06, Emmanuel Jourdan wrote:
>
> On 9 nov. 06, at 06:54, Dave Leith wrote:
>
> I have been needing to use regexp and the jit.str.regexp alot lately.
> There is one inconsistency (at least) that I don’t understand. It has to do
> with formatting the expressions with or without a @ Can somehelp here?
>
>
> Hi,
> your problem have nothing to do with regexp, but it’s related to the
> attributes. Attributes allow you to create an object with special behavior
> (instead of sending the messages via a message box and a loadbang…. or a
> loadmess). The syntax is the "@" sign followed by the name of the attributes
> and its arguments as you did on the left side of your patch. One cool thing
> about the attributes is that you can see what are the currents "values" of
> them while ctrl+option+click (alt+right click on windows) on the object.
>
> About the "why is there a no match outlet", look at the patch bellow, it
> removes the aiff extension on a "file" if it exists. If you can get the no
> match, it’s easier to deal with, if the regurlar expression failed.
>
> HTH,
> ej
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P message 635 501 26 196617 toto;
> #P newex 635 475 62 196617 prepend set;
> #P message 672 391 43 196617 titi.aiff;
> #P message 635 392 26 196617 toto;
> #P newex 635 425 202 196617 regexp @re ([^.]+)\\.aiff @substitute %1;
> #P fasten 0 3 3 0 784 454;
> #P connect 0 0 3 0;
> #P connect 2 0 0 0;
> #P connect 1 0 0 0;
> #P connect 3 0 4 0;
> #P window clipboard copycount 5;
>
>
>
>
>


November 9, 2006 | 6:37 pm

On 9 nov. 06, at 19:02, Dave Leith wrote:

> Thanks Emmanuel
>
> I still think there there are a few very strange things happening
> here. (I was aware of the attributes as I work with Jitter.) I have
> modified your patch to show these and hopefully clarified my patch
> to show also. Sorry for being thick about this I have ‘big’ plans
> for using the nomatch output. I hope you can help.

I can’t speak about the getstate/getattribute, I can imagine this
come with the OBEX externals stuff (Jeremy?). But I still doesn’t
understand why you don’t use the attributes for the regexp object,
the way you write the arguments it can’t work. try the following:

1) with this object in your patch:
regexp re \d substitute " "

2) ctrl+alt+click and look at the re and substitues attributes : it
says it is looking for the string "re" and it’ll substitute by "d"…

For the other part (see patch bellow), don’t forget there’s plenty of
ways to extract the same information with a regular expression. Some
are more efficient than other, and some may works faster but won’t
support possibility. You’ve to design the regular expression
specially for the type of inputs you’ll have. The "titi.aiff.aiff"
didn’t work because, I wasn’t expected this as input, now it’s
supported, but there’s still some issues (if the first extension is
not aiff for example) but it’s a choice (a compromise at least).

Best,
ej

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P hidden newex 309 277 68 196617 loadmess set;
#P button 429 252 15 0;
#P message 400 307 75 196617 toto;
#P newex 400 281 62 196617 prepend set;
#P message 220 100 62 196617 titi.aiff.aiff;
#P newex 523 268 62 196617 prepend set;
#P window linecount 0;
#P message 523 306 50 196617;
#P window linecount 1;
#P message 220 364 75 196617 titi;
#P newex 220 338 62 196617 prepend set;
#P message 262 155 47 196617 tutu.aiff;
#P message 237 128 26 196617 toto;
#P newex 220 217 251 196617 regexp @re ([^.]+)\\.aiff.* @substitute
%1;
#P connect 3 0 4 0;
#P connect 6 0 5 0;
#P connect 8 0 9 0;
#P connect 7 0 0 0;
#P connect 1 0 0 0;
#P connect 2 0 0 0;
#P connect 0 0 3 0;
#P connect 0 3 10 0;
#P connect 0 3 8 0;
#P connect 0 4 6 0;
#P hidden connect 11 0 5 0;
#P hidden connect 11 0 9 0;
#P hidden connect 11 0 4 0;
#P window clipboard copycount 12;


November 9, 2006 | 7:38 pm

On 11/9/06, Emmanuel Jourdan wrote:
>
> On 9 nov. 06, at 19:02, Dave Leith wrote:
>
> > Thanks Emmanuel
> >
> > I still think there there are a few very strange things happening
> > here. (I was aware of the attributes as I work with Jitter.) I have
> > modified your patch to show these and hopefully clarified my patch
>
> I can’t speak about the getstate/getattribute, I can imagine this
> come with the OBEX externals stuff (Jeremy?). But I still doesn’t
> understand why you don’t use the attributes for the regexp object,
> the way you write the arguments it can’t work. try the following:
>
> 1) with this object in your patch:
> regexp re \d substitute " "
>
> 2) ctrl+alt+click and look at the re and substitues attributes : it
> says it is looking for the string "re" and it’ll substitute by "d"…

Thanks that technique really helps!!

For the other part (see patch bellow), don’t forget there’s plenty of
> ways to extract the same information with a regular expression. Some
> are more efficient than other, and some may works faster but won’t
> support possibility. You’ve to design the regular expression
> specially for the type of inputs you’ll have. The "titi.aiff.aiff"
> didn’t work because, I wasn’t expected this as input, now it’s
> supported, but there’s still some issues (if the first extension is
> not aiff for example) but it’s a choice (a compromise at least).

Yah, thanks here too. Still can’t figure out why my example finds 2
substitutions but then outputs an unmatched output (like I made yours do).
For my purposes here it will be alright. It does seem to be how you write
the RE rules.

Best,
> ej
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P hidden newex 309 277 68 196617 loadmess set;
> #P button 429 252 15 0;
> #P message 400 307 75 196617 toto;
> #P newex 400 281 62 196617 prepend set;
> #P message 220 100 62 196617 titi.aiff.aiff;
> #P newex 523 268 62 196617 prepend set;
> #P window linecount 0;
> #P message 523 306 50 196617;
> #P window linecount 1;
> #P message 220 364 75 196617 titi;
> #P newex 220 338 62 196617 prepend set;
> #P message 262 155 47 196617 tutu.aiff;
> #P message 237 128 26 196617 toto;
> #P newex 220 217 251 196617 regexp @re ([^.]+)\\.aiff.* @substitute
> %1;
> #P connect 3 0 4 0;
> #P connect 6 0 5 0;
> #P connect 8 0 9 0;
> #P connect 7 0 0 0;
> #P connect 1 0 0 0;
> #P connect 2 0 0 0;
> #P connect 0 0 3 0;
> #P connect 0 3 10 0;
> #P connect 0 3 8 0;
> #P connect 0 4 6 0;
> #P hidden connect 11 0 5 0;
> #P hidden connect 11 0 9 0;
> #P hidden connect 11 0 4 0;
> #P window clipboard copycount 12;
>
>


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