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?

FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91
Randomblue
  • 112,777
  • 145
  • 353
  • 547
  • 2
    possible duplicate http://stackoverflow.com/q/1131918/777982 – TheTechGuy Jul 26 '11 at 02:09
  • There is no such thing as a "PHP regular expression" or a "JavaScript regular expression". – Lightness Races in Orbit Jul 26 '11 at 02:14
  • 1
    Hum. Well the above regular expression works with PhP but not with JavaScript. What's the problem? – Randomblue Jul 26 '11 at 02: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. – Alan B. Dee Jul 26 '11 at 02:22
  • There's no negative lookbehind in Javascript's regex, that's why it doesn't work. – Digital Plane Jul 26 '11 at 02:27
  • @Randomblue, Javascript has no lookbehinds, you can partly simulate that behavior with a capturing group tho. What exactly do you want to do with this? Could help porting it if you give us some more info on what you want to do and sample data. – Qtax Jul 26 '11 at 03:04

1 Answers1

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.

Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86