Forums > MaxMSP

regexp with ^ caret and $ dollar signs

June 15, 2010 | 1:00 am

Hi,

I’m having trouble to understand the exact behavior of the caret inside regexp.

regexp .$

This returns the last character of a string ("n" from "horn", "7" from "dx7", etc.). Sounds good to me.

regexp ^.

I would expect this one to return only the first character of a string, such as "h" from "horn" and "d" from "dx7". However, it outputs lists such as "h o r n" and "d x 7".

I’m certainly missing something here. Any help appreciated. Please see example patch below. I’ve searched other regexp-related posts in this forum, but this is not addressed directly.

– Pasted Max Patch, click to expand. –

June 15, 2010 | 2:21 am

The [regexp] object carries on searching regardless. If you want it to match only the first character you need to use the backreferences outlet and use something like regexp ^(.).*. This will match the whole word but only remember the first character, whatever it might be. If you don’t do this the object starts searching again from where it left off which leads to the results you pointed out.

lh


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