Regex to Perl regex

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Regex to Perl regex

Post 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?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Regex to Perl regex

Post 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})/
Post Reply

Return to “The Lounge”