Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7397 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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.

  • 2 weeks later...
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.