REGEXP, Can not compile regular expression

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Loginbug
Posts: 9
Joined: Tue Feb 02, 2010 7:36 pm

REGEXP, Can not compile regular expression

Post by Loginbug » Fri Nov 12, 2010 11:12 am

I have used the http://gskinner.com/RegExr/ to make this WORKING regular expression:
(?<=")http://mysite.com/.*?(?=")
It means Search for " input and exclude it, then search for http://mysite.com/, then search for any chars, ending with " iput, excluding it.This string match links that refer to mysite.com

But iMacros says error while compiling
SEARCH SOURCE=REGEXP:"(?<=")http://mysite.com/.*?(?=")" IGNORE_CASE=YES EXTRACT=$1
Why? :?:
Tom, Tech Support
Posts: 3529
Joined: Mon May 31, 2010 4:59 pm

Re: REGEXP, Can not compile regular expression

Post by Tom, Tech Support » Mon Nov 22, 2010 5:14 pm

Hi Loginbug,

Two observations: 1) Since the entire regular expression needs to be enclosed within quotes in the iMacros command, you need to escape the quote characters which are a part of your expression:

SEARCH SOURCE=REGEXP:"(?<=\")http://mysite.com/.*?(?=\")" IGNORE_CASE=YES EXTRACT=$1

2) iMacros for Firefox doesn't seem to be able to recognize the "lookbehind" syntax: ?<=
iMacros for IE and the iMacros Browser can both handle this syntax. I will log this an issue for the development team to investigate further.
Regards,

Tom, iMacros Support
Tom, Tech Support
Posts: 3529
Joined: Mon May 31, 2010 4:59 pm

Re: REGEXP, Can not compile regular expression

Post by Tom, Tech Support » Mon Nov 22, 2010 6:10 pm

Update:
Since iMacros for Firefox uses Javascript regexp engine and the engine does not support lookbehind, only lookforward is possible.
Therefore, the following macro will work in the iMacros commercial editions and iMacros for IE, but not in iMacros for Firefox:

Code: Select all

URL GOTO=http://www.iopus.com/imacros/demo/v6/extract.htm
SEARCH SOURCE=REGEXP:"(?<=Can)(adian)" IGNORE_CASE=YES EXTRACT=$1
PROMPT {{!EXTRACT}}
Regards,

Tom, iMacros Support
oobe
Posts: 5
Joined: Thu Apr 21, 2011 1:21 pm

Re: REGEXP, Can not compile regular expression

Post by oobe » Thu Apr 21, 2011 1:37 pm

I can't change to JavaScript :( (iMacros 7.2.1.0, Win7 x64, Firefox 4, demo: ok)

This is working

Code: Select all

SEARCH SOURCE=REGEXP:\"resourceTickerMetal = {\\W+available: (\\d+)\" EXTRACT=$1
after change.. doesn't:

Code: Select all

var macro;
macro =  "CODE:";
macro +=  "SEARCH SOURCE=REGEXP:\"resourceTickerMetal = {\\W+available: (\\d+)\" EXTRACT=$1" + "\n"; 
iimPlay(macro);
------------------------------ or ------------------------------
iimPlay("CODE: SEARCH SOURCE=REGEXP:\"resourceTickerMetal = {\\W+available: (\\d+)\" EXTRACT=$1");
var extract1 = iimGetLastExtract();
------------------------------ or ------------------------------
iimPlay("CODE: SEARCH SOURCE=REGEXP:\\\"resourceTickerMetal = {\\\\W+available: (\\\\d+)\\\" EXTRACT=$1");
var extract1 = iimGetLastExtract();
SyntaxError?: wrong format of SEARCH command, line: 1 (Error code: -910)
Please help
Tom, Tech Support
Posts: 3529
Joined: Mon May 31, 2010 4:59 pm

Re: REGEXP, Can not compile regular expression

Post by Tom, Tech Support » Fri Apr 29, 2011 2:20 pm

oobe,

You need to escape the backslash characters in your Javascript strings.
Regards,

Tom, iMacros Support
prabacse
Posts: 3
Joined: Wed Aug 28, 2013 3:32 am

Re: REGEXP, Can not compile regular expression

Post by prabacse » Fri Feb 28, 2014 6:09 am

http://www.samplein.com/company/1314096 ... dx%3A1-1-1

here i extract above URL using !CURRENTURL Tag.
i need help to exact company id i.e 1314096

help me as soon as possible ...

help with EVAL or SEARCH with REGEXP Tags...
chivracq
Posts: 8786
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

Post by chivracq » Fri Feb 28, 2014 4:20 pm

prabacse wrote:http://www.samplein.com/company/1314096 ... dx%3A1-1-1

here i extract above URL using !CURRENTURL Tag.
i need help to exact company id i.e 1314096

help me as soon as possible ...

help with EVAL or SEARCH with REGEXP Tags...
No need to ask your Question twice..., I reply in your dedicated Thread...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
BlueOne
Posts: 5
Joined: Sun Nov 29, 2015 3:35 pm

Re: REGEXP, Can not compile regular expression

Post by BlueOne » Sun Nov 29, 2015 3:46 pm

I have a similar problem but i didn't understand the Tech support's answer :-)

This imacros code works:

Code: Select all

SEARCH SOURCE=REGEXP:"De ([0-9]{1}&nbsp;[0-9]{3}&nbsp;[0-9]{3}&nbsp;€)" IGNORE_CASE=YES EXTRACT=$1
I want to adapt it in a javascript and play it with the plugin of imacros in firefox.
I tried few times but it didn't work because of the " " of the REGEXP.

Here my javascript code:

Code: Select all

extract ="SEARCH SOURCE=REGEXP:"De ([0-9]{3}&nbsp;[0-9]{3}&nbsp;€)" IGNORE_CASE=YES EXTRACT=$1"+ "\n";
Here the error:
SyntaxError: missing ; before statement, line 20 (Error code: -991)
I tried without the " " but i have an other error...

Could you help me ?
chivracq
Posts: 8786
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

Post by chivracq » Sun Nov 29, 2015 6:11 pm

BlueOne wrote:I have a similar problem but i didn't understand the Tech support's answer :-)

This imacros code works:

Code: Select all

SEARCH SOURCE=REGEXP:"De ([0-9]{1}&nbsp;[0-9]{3}&nbsp;[0-9]{3}&nbsp;€)" IGNORE_CASE=YES EXTRACT=$1
I want to adapt it in a javascript and play it with the plugin of imacros in firefox.
I tried few times but it didn't work because of the " " of the REGEXP.

Here my javascript code:

Code: Select all

extract ="SEARCH SOURCE=REGEXP:"De ([0-9]{3}&nbsp;[0-9]{3}&nbsp;€)" IGNORE_CASE=YES EXTRACT=$1"+ "\n";
Here the error:
SyntaxError: missing ; before statement, line 20 (Error code: -991)
I tried without the " " but i have an other error...

Could you help me ?
CIM...! :mrgreen:
=> iMacros for FF v8.9.4...?, FF42...?, OS...?

When converting an .iim Statement to a in a .js Script on the fly created Macro, you need to escape Special Characters and Double Quotes so I think here you need to escape the inner Double Quotes (or replace them with Single Quotes):

Code: Select all

extract ="SEARCH SOURCE=REGEXP:\"De ([0-9]{3}&nbsp;[0-9]{3}&nbsp;€)\" IGNORE_CASE=YES EXTRACT=$1"+ "\n";
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
BlueOne
Posts: 5
Joined: Sun Nov 29, 2015 3:35 pm

Re: REGEXP, Can not compile regular expression

Post by BlueOne » Mon Nov 30, 2015 4:01 pm

Hello chivracq,

Thank you for your answer.
I add / before and after the REGEX and it works !
Thank you very much for your help.

For information my CIM is Imacros for Firefox 8.9.4 on Mac OS ;-)
Last edited by BlueOne on Mon Nov 30, 2015 7:41 pm, edited 1 time in total.
chivracq
Posts: 8786
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

Post by chivracq » Mon Nov 30, 2015 5:19 pm

BlueOne wrote:Hello chivracq,

Thank you for your answer.
I add / before and after the REGEX and it works !
Thank you very much for your help.

But be careful the / have to be before the " at the beginning of the REGEX and after the " at the end of the REGEX.
I hope it's gonna help someone else.

For information my CIM is Imacros for Firefox 8.9.4 on Mac OS ;-)
Oh...!, so you mean like this:

Code: Select all

extract ="SEARCH SOURCE=REGEXP:/"De ([0-9]{3}&nbsp;[0-9]{3}&nbsp;€)"/ IGNORE_CASE=YES EXTRACT=$1"+ "\n";
OK, good to know, that must be MacOS specific, I reckon...

You didn't try with Single Quotes btw, either for the inner Quotes or for the outer Quotes...?
(I don't use 'REGEXP', I don't use .js Scripts, I don't use on the fly created Macros in .js Scripts, I don't have a Mac, so I cannot really do any Testing, ah-ah...! :oops: :cry: )
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
BlueOne
Posts: 5
Joined: Sun Nov 29, 2015 3:35 pm

Re: REGEXP, Can not compile regular expression

Post by BlueOne » Mon Nov 30, 2015 7:46 pm

Hi chivracq,

I update my post because your first solution was correct.
I was too tired when i write my previous post... :roll:

By the way i have a similar problem with a EVAL line maybe you could see what's the problem.

I want to transform this imacros code in javascript: (it's work)

Code: Select all

SET !VAR1 EVAL("var a=\"{{!EXTRACT}}\";a.replace(\"&nbsp;\",\"\");")
After few tries i write this javascript adaptation but still it's doesn't work... any idea ?

Code: Select all

extract +="SET !VAR1 EVAL(\"var a='{{!EXTRACT}}';a.replace((&nbsp;),())\")"+ "\n";
I'm sure is the same kind of problem... :oops:

Thanks
chivracq
Posts: 8786
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

Post by chivracq » Mon Nov 30, 2015 8:57 pm

BlueOne wrote:Hi chivracq,

I update my post because your first solution was correct.
I was too tired when i write my previous post... :roll:
Well, I'm not sure about my "first solution was correct", because I used Backslashes en even after your EDIT, you left a Forward Slash, so do you have to use Forward or Backward Slashes to escape Double Quotes...!?

Maybe easier if you post yourself your Working Solution... :idea:

And you still don't react about Single Quotes either for the inner or for the outer Double Quotes...
BlueOne wrote:By the way i have a similar problem with a EVAL line maybe you could see what's the problem.

I want to transform this imacros code in javascript: (it's work)

Code: Select all

SET !VAR1 EVAL("var a=\"{{!EXTRACT}}\";a.replace(\"&nbsp;\",\"\");")
After few tries i write this javascript adaptation but still it's doesn't work... any idea ?

Code: Select all

extract +="SET !VAR1 EVAL(\"var a='{{!EXTRACT}}';a.replace((&nbsp;),())\")"+ "\n";
I'm sure is the same kind of problem... :oops:

Thanks
For this one, this is very cumbersome, 'EVAL()' is a way to use JavaScript in pure .iim Scripts, you are already in a JavaScript "Environment" because you are creating an .iim Script on the fly in a .js Script (which I already find cumbersome, some "clever" Kid created such a Script years ago and posted it on some obscure Forum to impress other Script Kiddies and that Script has since gone Viral while hardly anybody understands how it works and they all come to the Forum with a Pb though I don't even use (and never have) those stupid :shock: Scripts), so you are now embedding JavaScript in an .iim Script embedded in JavaScript.

So either you use pure .iim Scripts like I do, if you need some Conditional Behaviour, well then OK..., it's OK to use a .js Script (even if I still stick to pure .iim and I do more complex things in pure .iim than I've ever seen in .js Scripts on the Forum...), but then you put the .iim part in an .iim Macro that you call with 'iimPlay()', especially if you still want to use some JavaScript in that .iim. Or you do the JavaScript part directly in your .js Script. Embed x3 is cruising for Trouble=Spanking...! :roll:

But for your thing, pfff, dunno, try stg like this:

Code: Select all

extract +='SET !VAR1 EVAL("var a='{{!EXTRACT}}'; a.replace('&nbsp;','');")' + "\n";
or:

Code: Select all

extract +="SET !VAR1 EVAL(\"var a=\\\"{{!EXTRACT}}\\\"; a.replace(\\\"&nbsp;\\\",\\\"\\\");\")"+ "\n";
And you may need to use Forward Slashes instead of Backslashes on MacOS, it's still not clear to me..., see my Comment to the first Quote...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
BlueOne
Posts: 5
Joined: Sun Nov 29, 2015 3:35 pm

Re: REGEXP, Can not compile regular expression

Post by BlueOne » Tue Dec 01, 2015 9:32 am

To clarify the situation :D

I wanted to adapt this imacros (.iim) for javascript (.js):

Code: Select all

SEARCH SOURCE=REGEXP:"De ([0-9]{1}&nbsp;[0-9]{3}&nbsp;[0-9]{3}&nbsp;€)" IGNORE_CASE=YES EXTRACT=$1
I simply had to replace " of the REGEX by \"
So i finally succeed with this code:

Code: Select all

extract ="SEARCH SOURCE=REGEXP:\"De ([0-9]{1}&nbsp;[0-9]{3}&nbsp;[0-9]{3}&nbsp;€)\" IGNORE_CASE=YES EXTRACT=$1"+ "\n";
I use Imacros for Firefox 8.9.4 on Mac OS
BlueOne
Posts: 5
Joined: Sun Nov 29, 2015 3:35 pm

Re: REGEXP, Can not compile regular expression

Post by BlueOne » Tue Dec 01, 2015 9:43 am

For this one, this is very cumbersome, 'EVAL()' is a way to use JavaScript in pure .iim Scripts, you are already in a JavaScript "Environment" because you are creating an .iim Script on the fly in a .js Script (which I already find cumbersome, some "clever" Kid created such a Script years ago and posted it on some obscure Forum to impress other Script Kiddies and that Script has since gone Viral while hardly anybody understands how it works and they all come to the Forum with a Pb though I don't even use (and never have) those stupid :shock: Scripts), so you are now embedding JavaScript in an .iim Script embedded in JavaScript.

So either you use pure .iim Scripts like I do, if you need some Conditional Behaviour, well then OK..., it's OK to use a .js Script (even if I still stick to pure .iim and I do more complex things in pure .iim than I've ever seen in .js Scripts on the Forum...), but then you put the .iim part in an .iim Macro that you call with 'iimPlay()', especially if you still want to use some JavaScript in that .iim. Or you do the JavaScript part directly in your .js Script. Embed x3 is cruising for Trouble=Spanking...! :roll:

But for your thing, pfff, dunno, try stg like this:
CODE: SELECT ALL
extract +='SET !VAR1 EVAL("var a='{{!EXTRACT}}'; a.replace('&nbsp;','');")' + "\n";

or:
CODE: SELECT ALL
extract +="SET !VAR1 EVAL(\"var a=\\\"{{!EXTRACT}}\\\"; a.replace(\\\"&nbsp;\\\",\\\"\\\");\")"+ "\n";

And you may need to use Forward Slashes instead of Backslashes on MacOS, it's still not clear to me..., see my Comment to the first Quote...
I am aware that this is not the most optimal thing to do ... :roll:
And thank you to share your experience with me.

Your second proposition works !!

Code: Select all

extract +="SET !VAR1 EVAL(\"var a=\\\"{{!EXTRACT}}\\\"; a.replace(\\\"&nbsp;\\\",\\\"\\\");\")"+ "\n";
Post Reply