Regular Expressions

BlitzMax Forums/BlitzMax Programming/Regular Expressions

Artemis(Posted 2005) [#1]
Hi.

Can I use Regular Expressions in Bmax?

is there any mod oder code in bmax or c which i can use in bmax?

-jonas


Will(Posted 2005) [#2]
What are regular expressions?

Also, is there an alternative for x = x + 1, like += in bmax?


xlsior(Posted 2005) [#3]
What are regular expressions?


Regular expressions are kind of a string comparison scripting language, which allows you to do very detailed string comparisons. They are invaluable for advanced pattern matching.

it allows a bunch of commands like:

. = any character
[AaBb] = will match either A, a, B or b
B[0-9]{5} = will match anything starting with B, followed by 5 numbers between 0 and 9
a(b)c = will match abc as well as ac

So a regular expression comparison could be something like: if A$="[Cc]olo(u)r[0-7]{1,3}".
This expression matches anything which starts with either an uppercase or lowercase C, then the lowercase letters 'olor' or 'olour', and followed by either 1,2 or 3 numbers ranging from 0 through 7.

That expression would return a match for all of the following:

Color000
colour172
Colour4

but not:

colour9
Color128
ColorABC

They can be very nice parsing conditional matches,especially when you're analyzing the output of other programs.

They were very handy to have when I was migrating 30,000 directories of user data from an old windows-based mailsite mailserver to a unix maildir system with a very different folder layout --
Thanks to the regular expressions I could easily analyze the filenaming schemes and move the correct files to the correct destination locations, despite having several million files to deal with.

They have also proven invaluable when it came to creating spam filters -- flagging (partial) matches of key items and their common obfuscations among tons of seemingly random drivel. Flagging 'random' spam domains that followed certain patterns like two-numbers-a-dash-three-letters-a-number-dot-[random-twenty-character-domain].dot-com. Detecting certain consistently malformed headers as generated by a particular spam program -- Regular expressions made it possible for me to block many millions of spam messages by looking for the occurances of certain known patterns. (on a mid-size ISP mailserver)

PowerBASIC for windows has regular expressions support built in, as do scripting languages like Perl and many of the unix command line tools like grep, awk and sed.

If there is a (free) regular expression parser available for BMax, I would like to hear about it...

Also, is there an alternative for x = x + 1, like += in bmax?


Yes:

x:+1 addition
x:-1 subtraction
x:*2 multiplication
x:/2 division

And some others... Check under 'variables' in the BMax help.


Artemis(Posted 2005) [#4]
hmm, there's an c/c++ lib here: http://www.boost.org/libs/regex/doc/index.html ( http://www.boost.org ) and here: http://www.pcre.org/ but i don't understand this


rdodson41(Posted 2005) [#5]

Also, is there an alternative for x = x + 1, like += in bmax?


x :+ 1