PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Regular expressions integrated in PPL

Regular expressions functions are now an integral part of PPL. Expect to see these cool functions starting with version 0.8 beta.

Code:
match(expression, string);
search(expression, string, begin$, end$);
subexpcount();
subexp(string, index, begin$, length$);

PPL implements the following expressions:

\ Quote the next metacharacter
^ Match the beginning of the string
. Match any character
$ Match the end of the string
| Alternation
() Grouping (creates a capture)
[] Character class

==GREEDY CLOSURES==
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times

==ESCAPE CHARACTERS==
\t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)

==PREDEFINED CLASSES==
\l lowercase next char
\u uppercase next char
\a letters
\A non letters
\w alphanimeric [0-9a-zA-Z]
\W non alphanimeric
\s space
\S non space
\d digits
\D non nondigits
\x exadecimal digits
\X non exadecimal digits
\c control charactrs
\C non control charactrs
\p punctation
\P non punctation
Here is a little example on how to use the regular expressions functions with PPL.

Code:
// Regular Expressions test

string$ = "Bill Clinton";
expr$ = "^(Bill|George|Renald) (Clinton|Bush|Reagan)$";

ShowMessage(search(expr$, string$, b$, e$));
ShowMessage(b$+","+e$);
i$ = 0;
while(i$ <= subexpcount - 1)
subexp(string$, i$, begin$, len$);
ShowMessage(begin$ + "," + len$);
i$++;
end;
PointOfLight · 27 Aug 2004, 21:28 UTC
You know, I've never quite understood regular expressions, but I guess this gives me one more reason to learn them!