1

I just started working with RE in javascript. I created a the syntax in a prog called RegExr from gskinner.com and and it's work perfectly fine in it, with my test data, but in javascript in throws "invalid quantifier" error. From what I can understand it probably means ther is unescaped special chars. I've been searching the whole day with no success. I am posting my code as I had it in RegExr, as I think my attempts will only make thing more difficult. Please help me.

Code:

data = data.replace( /(Photo)|(?<=Photo:)(.+?)(?=Stock)|(Stock Code)|(?<=Stock Code:)(.+?)(?=Make:)|(Make)|(?<=Make:)(.+?)(?=Model:)|(Model)|(?<=Model:)(.+?)(?=Year:)|(Year)|(?<=Year:)(.+?)(?=Price:)|(Price)|(?<=Price:)(.+?)(?=Description:)|(Description)|(?<=Description:)(.+?)(?=Photo:)|(?<=Description:)(.+?)(?=$)/g, "");

Thanks in advance. Jacques

5
  • 8
    JavaScript does not support lookbehind assertions (?<=). Commented Jan 28, 2011 at 14:08
  • What should your regex do? There is a lot of stuff there that can't be what you indendet. E.g. the second alternative "(?<=Photo:)(.+?)(?=Stock)" will never match, since it depends on "Photo" being present, but that will be caught (and replaced by nothing) earlier... Commented Jan 28, 2011 at 14:47
  • Hi Jens, sorry it shouldn't replace but match. I've got a string looking like this: Photo:http:xxxx.xxx/images/photo.jpgStock Code:001Make:AlfaModel:JuliettaYear:2011Price:240000.00Description:Brand NewPhoto:xxxx.xxx/images/photo2.jpg.... I want to ultimately convert it into a json string to pass via jquery ajax call to a asmx webservice. {['Photo':'xxxx.xxx/images/… New'],['Photo':'xxxx.xxx/images/…} Hope that makes sence. Commented Jan 30, 2011 at 15:24
  • After doing some reseach it seems that it would be much easier sending the whole string to the webservice and then do the regex there as it seems that vb.net has better support for things like the "lookbehind assertions" like what BoltClock said jscript does not support. Commented Jan 30, 2011 at 15:28
  • The JSON example you provide in your comment is not legal JSON. Commented Jun 10, 2011 at 3:52

1 Answer 1

1

In the interest of closing this question, like @BoltClock correctly stated. "JavaScript does not support lookbehind assertions (?<=)."

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.