Page 1 of 1

Regex to Perl regex

Posted: Tue Jul 22, 2014 12:01 pm
by wmdvanzyl
Hi All.

I have a question about regex - and no, it's not about parsing html. :p

So i have a regex that i want to convert into a Perl regex. This is related to field validation in the Formbuilder module. Formbuilder requires Perl regex. So my regex is

Code: Select all

[0](\d{9})|([0](\d{2})( |-)((\d{3}))( |-)(\d{4}))|[0](\d{2})( |-)(\d{7})
It says: 0 followed by 9 digits OR 0 followed by 2 digits and then 3 digits and then 4 digits OR 0 followed by 2 digits and then 7 digits

Question: Is this acceptable to use as is in Formbuilder; and if not, what should the Perl equivalent regex look like?

Re: Regex to Perl regex

Posted: Tue Jul 22, 2014 2:16 pm
by velden
It could work, note that it needs separators around it. Often a / is used:

Code: Select all

/[0](\d{9})|([0](\d{2})( |-)((\d{3}))( |-)(\d{4}))|[0](\d{2})( |-)(\d{7})/