regexp question (truly exact match ?…)
after having done some serious research in the forum and the web concerning regexp code i still haven’t found the solution for this (i hope) very trivial problem:
i want to check, if a sentence (i.e. a string) contains the word "there".
as i am looking for an exact match i surround it in b boundaries so the object looks like this:
the problem is, that strings like "there’s a xxx" are also matched. could anybody help me modifying the regexp so that apostrophes are excluded ?
(the general issue here is that i really miss something like a NOT operator in regexp… or did i just overlook something ?)
thanks for any hint !
The caret or ^ is a not operator just within a pair of square brackets 
I forget exactly how regexp works a lot of the time so whenever I want to write a regexp I end up here:
I’m not really familiar with regexp but it seems to me you have to include the space’s in front of, and after "there" so it will only include "stand-alone" there’s
Like this; " there "
thanks a lot for your reply. only … it doesn’t work ;-)
the problem here is that with this caret in brackets REGEXP searches for an extra element, whereas i want it to match exactly after "there" and not match after "there’s"
i.e. the formula
wouldn’t match "there" anymore
You probably need to roll your own version of \b possibly making use of the pipe operator to match several slightly different scenarios.
Start by enumerating *exactly* when you want it to match and when not.
This might work:
This should match at the start of the input or after a non-word character except ‘
Same kind of thing at the end.
Might have got it wrong though – haven’t tested it.
yeah ! that really seem’s to work ! i did no heavy testing yet, but the example strings behave like they should!
thanks a lot, alex !
(but hey, what a monster of regexp code, really ugly to look at …)
you also *might* be able to do it with numbers through [atoi]. Run the whole string through [atoi] and you’ll get a list of the "number-chars", then try [zl sub] to compare the list to the word "there" (also run through [atoi], which gives 32 116 104 101 114 101 32, including spaces at beginning and end). So you’d be looking for that group of values in the master list, and [zl sub] will give you "found: 1" and "position: 10" or wherever.
----------begin_max5_patcher---------- 801.3oc2XtzbaBCD.9ryL4+fFtzKtczCd1a82QSlNXrhQsfjGPtIMY5+8hVg ejjhAWiLd5APvJjzpOsZ2U7xs2Lyag5IdsG5ynuhlM6kFIy.YFIy1JXlWY5S YEo0vG5UxqqSWw8l2Vol+jFpnlK0bYFG8XtHKGUJVkqQ4o+jqy4UbgTn20F4 lR0FcAWCcIYqXqL8uVyspjmG59s08fRpkokPMdeoRjVrq2DKAgpEe+ijjcRW WwMZTpVnjeqhmos8IMJ9S34nnPycb6sWOL0hmgggPapduFKjaUX5twHUmkKj qNn+YTloSiSL2oDXvL2Q2Cs422dioroX94SbdQM+Bvz39XJgBzz2ULkvnP+C vzG6Rj1oQLBrh+PMRHQWDK4ndsjCAdSibkkLNvzoAVKYVnKwN.2K.TC6CpQv t2f.GwzX7AFxAi.QyTkkMSi+lgblRtrCjhOQrEzqsHI4rsEIGgaTeB.Kqe.6 XgcC3xJDY+.8fnpVORzy2a73.fAX9GDNBTPxerQEeODVWIjZzZUsvrPORbfN dbfv7gYOEJhRbNJdPsYz1MQFQ6Aa1FsbHLxgb34BT8lEcf.Z29nm+O3mN1az 73RwXKTrddoi.g5LJFgDfHXBhPvMWg6dNIAdjQady7neyUfUpOHEm.RHXls1 l1Bh8QIQMuE21Sgss07baooUlQCJ2GcqPHa7+uQB5Ey4wUGP7AvakM5pChqR s4dR7gc.LazHirIHGwKUFhgCD5TpyRPDVNYstfFii5zkymTsRbxDsPzDB+To Zz.op+4PU1QMksGvA6u+LUtxgE3Q58dUXT2a852+gJg8xwtx505ifz53Hl4x i2bmWqqg675irKVkoJTUs53gy84lW2CfyeIfMdQYIvYYrdeCw+W3H3DyR6na osmzqMEjt2QaUQH38a+obPuZp3MPqVsoJa67b6e.CcfYxRdsVHgMWG7UQu9i xEKWxkuJW1Rwx0plLeaUjisTNbcKdH5FYZzsnqXtEd8xsgsjRmLcizqtMMba PlawSi41PUMxEW0Bud2jNnEzfIgZCZA0eRTM1kwylQPSwePHmpO9 -----------end_max5_patcher-----------
Don’t bother with the b and stuff..
If you only want to check for "there" in a sentence then all you need to do is tell the regexp that it should look for "there" where ‘something’ obviously is whatever it is; its not of your concern.
So: "^*.there.*$" (no "", but see snippet below).
This means: From the start of the sentence (^) check for whatever kind of character (.* (. any character and * "one or x appearances")) until you get to a point where some letter combination needs to be there (‘there’). After this combination any kind of characters can appear until the end of the sentence ($).
And because you want to pinpoint to ‘there’ you want to use () so that it becomes a back reference.
Alas, here’s my proof of example:
----------begin_max5_patcher---------- 510.3ocyV10aaBCEF9ZpT+Obl0j5Ghgrg7Aq2sKyufcwTWkS3TvqfMB6njtp 8eeF6PaZKoMaMJIWPrz6wX+5Gd4Pd3zSBHSUKQMAtB9ADD7fUIvo0pDzIDPp 3KmUx0tIRpPslmijvUEM3RiqvD3VtnDyfJtoHDLEXCJUF3NoZATXuLJXtFAg wWK5wkPj4V.0ze8E1vGUkyqTyMknwsurN4aURiV7azIFGQ6z8y0beM5OODBb cWsZtYVgPleSCNy3KmLxdqP7.2uiRZGXoQzmtm18QxqbqF4aMBd45NSH6LVr S7OmdR6ncH7iSxu2hGXBvqBAoBTRzAQMb0E8xrj8DyRG2hogNxwFM3PvLItv djeMxpaDRSuvgsA3PeO3zC.XITWdg1NMHwGdn+ODfs6SMm4dq5L3dNjq9Tur ftmBJq3DarKvLN8XJoXfo8wlzcFZlxk4aGdF7005AcrDilX6NKj2Ya+TIxKr zB8sqgEEnz0TpO7suZAwhcspSG5iTGUIqFLGWVC+L5xycD6hnK+buuFtAVM7 emUgu35sYG024N1m9X6vbmeEHkB4q96DNizV3EHUql2Lq6fz8oeXMujgZiPx MBkb8Y87IUHxxP4y5mWIxpU1uFrxHv0a9A816sjiWuktUVidX3FcqL2A5gpc WYum2ROHVaOE2ZErC+U.815e -----------end_max5_patcher-----------
Edit: The trigger object doesn’t have to be there, but I used it here to make my example as easy to understood as possible.
That last example will match "theremin" and "weathered" though. You probably need to include all the punctuation you don’t mind preceeding/following the word in non-capturing brackets (or the option of it being the very first or last character) like so:
hi, regexp gurus !
thanks a lot for joining into this discussion and for all your nice help. now i already gained way more inside into the whole thing than i had before.
concerning the simplicity of the task i always re-learn that regular expression is really quite a beast to tame …
cheers, guys !
sorry, should have been "insight"
greetings from the land of PISA loosers ;-)
Forums > MaxMSP