REGEXP, Can not compile regular expression

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.

Moderators: iMacros Moderators, Community Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

REGEXP, Can not compile regular expression

by Loginbug on Fri Nov 12, 2010 4: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? :?:
Loginbug
 
Posts: 9
Joined: Tue Feb 02, 2010 12:36 pm

Re: REGEXP, Can not compile regular expression

by Tom, Tech Support on Mon Nov 22, 2010 10:14 am

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: 3326
Joined: Mon May 31, 2010 9:59 am

Re: REGEXP, Can not compile regular expression

by Tom, Tech Support on Mon Nov 22, 2010 11:10 am

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
Tom, Tech Support
 
Posts: 3326
Joined: Mon May 31, 2010 9:59 am

Re: REGEXP, Can not compile regular expression

by oobe on Thu Apr 21, 2011 6:37 am

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
oobe
 
Posts: 5
Joined: Thu Apr 21, 2011 6:21 am

Re: REGEXP, Can not compile regular expression

by Tom, Tech Support on Fri Apr 29, 2011 7:20 am

oobe,

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

Tom, iMacros Support
Tom, Tech Support
 
Posts: 3326
Joined: Mon May 31, 2010 9:59 am

Re: REGEXP, Can not compile regular expression

by prabacse on Thu Feb 27, 2014 11:09 pm

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...
prabacse
 
Posts: 3
Joined: Tue Aug 27, 2013 8:32 pm

Re: REGEXP, Can not compile regular expression

by chivracq on Fri Feb 28, 2014 9:20 am

prabacse wrote:http://www.samplein.com/company/1314096?trk=tyah&trkInfo=tas%3ATagle%2Cidx%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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 7461
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

by BlueOne on Sun Nov 29, 2015 8:46 am

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 ?
BlueOne
 
Posts: 5
Joined: Sun Nov 29, 2015 8:35 am

Re: REGEXP, Can not compile regular expression

by chivracq on Sun Nov 29, 2015 11:11 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 7461
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

by BlueOne on Mon Nov 30, 2015 9:01 am

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 12:41 pm, edited 1 time in total.
BlueOne
 
Posts: 5
Joined: Sun Nov 29, 2015 8:35 am

Re: REGEXP, Can not compile regular expression

by chivracq on Mon Nov 30, 2015 10:19 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 7461
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

by BlueOne on Mon Nov 30, 2015 12: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
BlueOne
 
Posts: 5
Joined: Sun Nov 29, 2015 8:35 am

Re: REGEXP, Can not compile regular expression

by chivracq on Mon Nov 30, 2015 1: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 7461
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: REGEXP, Can not compile regular expression

by BlueOne on Tue Dec 01, 2015 2: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 8:35 am

Re: REGEXP, Can not compile regular expression

by BlueOne on Tue Dec 01, 2015 2: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";
BlueOne
 
Posts: 5
Joined: Sun Nov 29, 2015 8:35 am

Next

Return to Data Extraction and Web Screen Scraping

Who is online

Users browsing this forum: No registered users and 3 guests

-->