-4

This code is working for c#. when we are coming to java script it is not working.

regular expression in c#.

string regExp ="^(?!(\d)\1+$)(?!(012345678901|123456789012|234567890123|345678901234|456789012345|567890123456|678901234567|789012345678|890123456789|901234567890)$)(?!\d{9}000$)\d{12}$"

Somebody help me how to convert this into JavaScript.
Please let me now any conversion tool is there.

5
  • 1
    Could you show what you tried so far, how does your converted expression look like, and with what input data you tried it that didn't match which was matching in C#? Commented Jun 16, 2013 at 13:47
  • That's an interesting regex, what are you using it for? Commented Jun 16, 2013 at 13:53
  • 2
    Hint: Javascript doesn't support look-behind assertions. See stackoverflow.com/questions/5973669/… Commented Jun 16, 2013 at 13:54
  • @Faust: So? There is no lookbehind assertion in that regex. Commented Jun 16, 2013 at 13:54
  • @Tim: Sorry, it's lookahead -- ?!, and I didn't realize that these are supported, where lookbehinds are not. I stand corrected. Commented Jun 16, 2013 at 20:07

1 Answer 1

4

There is a conversion tool available: RegexBuddy; it's not free, though (but totally worth it IMO).

Your regex is fine, you just need the proper JavaScript syntax:

var myregexp = /^(?!(\d)\1+$)(?!(012345678901|123456789012|234567890123|345678901234|456789012345|567890123456|678901234567|789012345678|890123456789|901234567890)$)(?!\d{9}000$)\d{12}$/;
Sign up to request clarification or add additional context in comments.

2 Comments

Wow! I didn't know that RegexBuddy can do that! Where is this conversation option in RegexBuddy program? I couldn't find it.
@SonerGönül: You can paste a regex from any flavor ("Paste regex from a ... string" etc.), then click the "Use" tab and choose your output language. Done.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.