1

This is the PHP regular expression I would like to convert into a JavaScript regular expression:

/(?<!\..|\...|\....)([\?\!\.]+)\s(?!.\.|..\.|...\.)/u

Are there tools to do such a conversion?

6
  • 2
    possible duplicate stackoverflow.com/q/1131918/777982 Commented Jul 26, 2011 at 2:09
  • There is no such thing as a "PHP regular expression" or a "JavaScript regular expression". Commented Jul 26, 2011 at 2:14
  • 1
    Hum. Well the above regular expression works with PhP but not with JavaScript. What's the problem? Commented Jul 26, 2011 at 2:15
  • 1
    There are, unfortunately, some slight differences between JavaScript's regexp engine and PHP's regexp engine. But true, regular expression "should" be universal between languages. Commented Jul 26, 2011 at 2:22
  • There's no negative lookbehind in Javascript's regex, that's why it doesn't work. Commented Jul 26, 2011 at 2:27

1 Answer 1

2

(?<!stuff goes here) is a negative lookbehind which isn't supported by JavaScript's regex implementation. There are some ways to mimic it, but it does not work properly for all cases - yours looks like one of those to me.

If you want to keep using this specific regex, but from JavaScript, you could consider simply passing the string to PHP using Ajax, which would then run the regex on it.

Sign up to request clarification or add additional context in comments.

Comments

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.