regular expressions

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
marielle
Livecode Opensource Backer
Livecode Opensource Backer

regular expressions

Post by marielle » Fri Mar 02, 2007 11:02 am

Somebody asked me via private email about this:
I want to filter a string to get rid of non-word-constituent characters (#,$,@,%, etc.). Can you please tell me how to do it?
The answer is \W \w stands for any word constituent character. The convention is to have in uppercase the exact complement of the set in lower case.

Note that if you are a speaker of a language that includes diacritic characters (é,à,ñ), these characters will be discarded as well.

Code: Select all

put replacetext("aeiouéñß","\W","")
-> result is "aeiou"
To be on the safe side, you may want to provide the exact list of characters to ignore:

Code: Select all

put replacetext("ae$iou%éñß","[#$@%]","")
--> result is "aeiouéñß"
\d stands for a digit. \D stands for anything *but* a digit
\s stands for any spacing character (space, tab, etc.) \S stands for anything *but* a spacing character.

You can check out my personal notes on regular expressions for more information. There are some extra tutorials at the bottom of that page.

Post Reply

Return to “Talking LiveCode”