Forums/How Do I ... ?

Support for regular expression syntax?

Jared White
posted this on September 29, 2011, 17:56

My question actually revolves around trying to remove leading zeros in formatted data (like 9.2.11 instead of 09.02.11) -- but the broader question is, does Webvanta script allow for any kind of text processing using regular expression? That'd be a great feature if not.

Thanks,

Jared

 

Comments

User photo
Christopher Haupt
Webvanta

Jared,

There is a very simple regex format option available for most data access tags (those that return a value). User format="gsub('regex','substitution')" as the attribute.

The 'regex' part supports most standard PCRE - Perl Compatible Regular Expressions. The formatter was meant for fairly simple expressions, and currently has some shortcomings (e.g. dealing with quotation marks--the quotes are optional around the expression and substitution, but are required if you need to include a comma, for instance).  

I haven't tested this, but try: 

gsub( '0?(\d)\.0?(\d)\.(\d{2})', '\1.\2.\3' )
September 29, 2011, 20:10
Jared White

Hi Chris,

Sorry I didn't respond to your helpful comment. This is good to know! The one problem though is I'm accessing the date field like so:

w:get name="start_date" format="%m.%d.%y" / >

So I'm not sure how to format the format...I tried putting this in a variable with w:var ... and then putting format on that, but that didn't work. Thanks in advance if you have any tips about that.

November 22, 2011, 16:33
User photo
Christopher Haupt
Webvanta

No worries, from WebvantaScript, you can get that immediately:

w:get name="start_date" format="%-m.%-d.%y" / >

Note the minus symbols. 

November 22, 2011, 16:50
Jared White

Awesome. That totally works!

November 23, 2011, 11:37