regular expressions problem

Hi all
I could sure do with some help on this!!!
I am having a big problem with getting freeway to recognise a quantifier that is marked as lazy.

So my example is this:

 /bproduct=(.+?)"/

which should restrict the expression to finding the first word which matches the word boundary of:

 product 

then the

 .+?

selects any character except a line break and and then stops at the first

"

character it comes across.

So with the above Expression
/bproduct=(.+?)"/

I used it on this:

`

myimage

`

what it should grab is this chunk:

product=My%20product%20name&price=100.00&qty=1&return=%23/index.html&units&currency=0&tax=0"

and it should stop at the quote mark after word tax, and using the online application http://www.regexr.com
it does exactly what I want it to do.

But in freeway, it doesn’t stop at the first quote mark it finds… it basically grabs everything from the word product up until the last
quote which is this alt=“myimage”

product=My%20product%20name&price=100.00&qty=1&return=%23/index.html&units&currency=0&tax=0"><img id="myimage" src="Resources/screenshot201410.jpeg" width=95 height=51 alt="myimage"

SO my question is can anyone see anything wrong in the expression and or does freeway not recognise lazy qualifier ? character
if it doesn’t then what do I use instead ?

any help would really be appreciated cos Ive been on this for blooming hours and its holding me up big time.

aaaaahhhhrrrrr !#¢#@*%!!!

max :o)


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
I can certain sympathise as I’ve spent many a long hour staring at regular expressions in Actions trying to get them to do something useful. Don’t get me wrong, they are very powerful and perfect when they work but I often spend longer creating and testing them than I would if I did the job with a lot more code and could step through it a line at a time.

I suspect that the JS interpreter in Freeway doesn’t fully understand the regexp and it falls back to being too greedy and finally matches the final quote in the string.

You could try reducing the regexp to a simpler form (something I can understand maybe) in the hope that Freeway does too.

Have you considered chunking the value of the href with something like this (untested) code;

var myhref = “http://ww3.aitsafe.com/cf/add.cfm?userid=123456789&#38;config=58262193&#38;product=My%20product%20name&#38;price=100.00&#38;qty=1&#38;return=%23/index.html&#38;units&#38;currency=0&#38;tax=0”;
var myhrefTrimmed = myhref.slice(myhref.indexOf(“?”,-1));
var myhrefArray = myhrefTrimmed.split(“&”);

/*
myhrefArray should now contain an array of name=value strings
which you can iterate through and split looking for values etc
*/

Another option is if you are doing this in an Action then look for the Action on the page and ask it for the value right from the UI rather than read it from the page code. You should be able to do this at design time so you’ll need to do a LOT less HTML manipulation.

It really depends on what you are looking for and how you want to use the data once you’ve found it.
I hope this helps. If not get back in touch and I’ll try again.
Regards,
Tim.


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try:

/product=[^”]*"/

It’s usually easier match everything but the thing you want to stop at, particularly when you know there can’t be another of those characters in the thing you’re trying to match.

Joe


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi tim and joe thanks for the input I have to say this has turned out to be a real hard nut to crack

Joe the code is working buts causing a javascript error
so I am going through everything again to see what casuing the error
again thanks for the help
kind regards max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

What’s the error?

On 10 Oct 2014, at 21:14, max email@hidden wrote:

Hi tim and joe thanks for the input I have to say this has turned out to be a real hard nut to crack

Joe the code is working buts causing a javascript error
so I am going through everything again to see what casuing the error
again thanks for the help
kind regards max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
Check that you don’t have an orphaned double quote in your code. These are quite valid in your Action code but the JS interpreter in Freeway will have a fit if encounters one.
Post a screen shot of the error and we should be able to see the context of the error in the code.
Regards,
Tim.

On 10 Oct 2014, at 21:14, max wrote:

Joe the code is working buts causing a javascript error


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Joe and Tim
After a lot of testing and retesting I have narrowed down the error was being caused by the orphaned double quote (as you suggested Tim) it didn’t matter what I did in terms of escape characters, freeway would throw a wobbly if I included the last double quote in the replacement code which meant the html which was being written was invalid. So in this specific scenario I couldn’t use the alternative RegEx. What I did in the end was to revert back to my original and look for different patterns which I could use as my word boundaries with a view that what ever I used Freeways RegEx would be greedy and therefore the patterns needed to be unique.

Its done now thank goodness!!! SO a big thank you for heading me in the right direction… without Joe’s alternative, I wouldn’t have realised what was wrong with the original and for his alternative code, which would normally have worked perfectly… and for Tim’s insight of where it may be a problem in this specific case. Certainly without both your help, I wouldn’t have thought about the approach I would eventually need to take.

Thank you both for your input and speak soon

max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Glad you got it working. If you come across an orphaned double quote in the future you can put the following at the end of the line (after the semi-colon):

// “

Hope this helps,
Joe


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

If you’re reading that as an email then it’s been automatically converted to a curly quote. Should be a straight one, of course.

Joe

On 14 Oct 2014, at 10:17, Joe Billings email@hidden wrote:

Glad you got it working. If you come across an orphaned double quote in the future you can put the following at the end of the line (after the semi-colon):

// “

Hope this helps,
Joe


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Oh blooming hell
a double forward slash !!! I tried the old ’ writing as an escaped character &quote; etc etc I didn’t think about a double \
thanks’ for that max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

core blimey all those came out wrong any way I tried everything i could think of apart from what you wrote
speak soon max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options