1

I'm having the below Regex which is written to support the ECMAScript Javascript flavour. However, this has to be re-written in the Perl flavour (PCRE) / (PCRE2)

(?<!x)(?<!\border\D*\W*)(?<!\border\D*number\W*)(?=(?:[._ –-]*\d){9})(?!9|66\D*6|00\D*0|(?:\d\D*){3}0\D*0|(?:\d\D*){5}0(?:\D*0){3})\d(?:[._ –-]*\d){4}

The above regex has Set of rules in it, Regex Demo here

I don't have an idea in Perl on how to implement it, however if i could get a help on this, it would be great!

1 Answer 1

2

You may use this PCRE compliant regex equivalent of your Javascript regex:

\border(?:\s*number)?\W*\d+(*SKIP)(*F)|(?<!x)(?=(?:[._ –-]*\d){9})(?!9|66\D*6|00\D*0|(?:\d\D*){3}0\D*0|(?:\d\D*){5}0(?:\D*0){3})\d(?:[._ –-]*\d){4}

RegEx Demo

  • The idea of the (*SKIP)(*FAIL) trick is to consume characters that you want to avoid, and that must not be a part of the match result.
  • (*F) shorthand for (*FAIL)
Sign up to request clarification or add additional context in comments.

11 Comments

Good old SKIP FAIL :-)
Thanks, that's the only work around for dynamic length lookbehind of JS
@anubhava, I worked on it, and got this to work. (\border\D*\W*)\d+(*SKIP)(*F)|(\border\D*number\W*)\d+(*SKIP)(*F)|(?<!x)(?=(?:[._ –-]*\d){9})(?!9|66\D*6|00\D*0|(?:\d\D*){3}0\D*0|(?:\d\D*){5}0(?:\D*0){3})\d(?:[._ –-]*\d){4} hope i didn't do anything wrong and make it more complex. Thoughts?
@anubhava, thank you very mutch for your explanation
@anubhava, i have posted the new question.. You can find it here link
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.