BaH.RegEx - Regular Expressions

BlitzMax Modules Forums/Brucey's Modules/BaH.RegEx - Regular Expressions

Has been updated to PCRE 7.4, although I've just noticed they've released 7.6 the other day, so expect another update in the not so distant future :-p

For the uninitiated, Regular Expressions are an extremely powerful method of search/replacing in strings.

Here's a complex example, just to show you what it can do :

Imagine you wanted to be able parse a string for dates in format dd/mm/yyyy or dd/mm/yy, and replace those entries in the string with the year only inside quotes. Writing a program to do that would be quite involved.

Now let's look at such a program using Regular Expressions :
SuperStrict

Framework BaH.RegEx
Import BRL.StandardIO

Local date:String = "The dates are: 12/30/1969, 06/04/1974 and 15/08/1980"
Print "Original : " + date + "~n"

Local regex:TRegEx = TRegEx.Create("(\d\d)[-/](\d\d)[-/](\d\d(?:\d\d)?)")

Print regex.replaceAll(date, "~q\3~q")

would result in the output :
Original : The dates are: 12/30/1969, 06/04/1974 and 15/08/1980

The dates are: "1969", "1974" and "1980"


The difficult part is learning how to write the regular expression, but there are good tutorials online, as well as an in-depth guide included with the module.

Have Fun ! :-)