The Shadow Posted August 16, 2004 Share Posted August 16, 2004 I've always loved using perl's regular expressions for finding matching bits of text. Now, with FM7 and custom functions, I was able to re-create a (somewhat simplified) version of perl's regular expression matcher completely with custom functions. You can download the file (which includes an explanation of the supported syntax) from my website: http://www.spf-15.com/fmExamples/ (see "Perl-style Regular Expressions") To use it, you call the RegexMatch custom function like so: RegexMatch( "[email protected]"; "((w+)@w+.(w+))" ) The result is a property list that pulls out the grouped pieces, or empty to indicate no match was possible. In this case the result is: $2=mark $3=com [email protected] The RegexMatch function implements the following regular expression syntax: @ - any single character (like FM find mode) # - any single digit (like FM find mode) s - a single whitespace character (perl) S - any non-whitespace character w - any word character (a..z, A..Z, 0..9, and underscore) W - any non-word character [a..z5..9 ] - build you own character class [^0..9] - inverted character class ? - the previous character or group is optional * - zero or more occurrences of the previous char or group + - one or more occurrences of the previous char or group I hope to continue to extend this set to become even more perl-like in the future. Suggestions or bug reports are welcome. Link to comment Share on other sites More sharing options...
The Shadow Posted August 24, 2004 Author Share Posted August 24, 2004 I've extended this example with a new function: Link to comment Share on other sites More sharing options...
Recommended Posts