RegEx fun in Real Studio

      No Comments on RegEx fun in Real Studio

I’ve always been inspired by the power of regular expressions … it’s just that I’ve never really needed them for anything extensive. I could always hack my way around the simple string replacements in the programming language I was using.

Today was different, however. I am working on an application that needs to validate a domain name. I should note that this is just for US based domain names so I haven’t coded it for Unicode. That’s for another day. Take a look how easy it is to do in Real Studio:

DIM cDomainName AS String = "Reg+#(Ex Is Hard, and you!can'tClean$This*@*(#String"
DIM cNewDomain AS String = ""
oRegEx.SearchPattern = "[^A-Za-z0-9-.]" // Basically allow any alphanumeric characters plus a dash and a dot
oRegEx.ReplacementPattern = ""
oRegEx.Options.ReplaceAllMatches = True
cNewDomain = oRegEx.Replace( cDomainName )

There. I’m a RegEx expert! Right?!?! Perhaps not. But this is a great simple introduction to RegEx for us mere-mortals.

Leave a Reply