JS Question: How to use ReG Exs to do comparisons

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Post Reply
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

JS Question: How to use ReG Exs to do comparisons

Post by additional001 » Thu Dec 11, 2014 7:17 pm

So I've sort of hit a road bump. I'm using extracted data to check against a static variable. Even though the variables look identical they are not and my while loop is not working. So I figure it would just be easier to have a variable that is a regular expression that matches my extracted data and then do a comparison.

So what I need is a very simple example of how to use a regular expression on a variable and have it match every time so long as it has "Standby" in it preferably in a while loop.

I've tried searching w3schools and I just can't wrap my head around how to apply the examples they give to what I need the Reg Ex for.

There doesn't seem to be an example on how to do this in a comparison statement for JS that I can find!

TIA
Tom, Tech Support
Posts: 3601
Joined: Mon May 31, 2010 4:59 pm

Re: JS Question: How to use ReG Exs to do comparisons

Post by Tom, Tech Support » Thu Dec 11, 2014 10:43 pm

Hi additional001,

If I understand you correctly, and I'm not sure I follow your description 100%, you would use something like the following:

Code: Select all

var extracted = iimGetExtract();

while (extracted.search(/Standby/) != -1)
{
// Code to be performed each time through the loop
}
Updated 2014-12-12: Changed iimGetLastExtract to iimGetExtract.

In this example, the loop will keep executing as long as the extracted data contains the text "Standby".

https://developer.mozilla.org/en-US/doc ... ing/search
Regards,

Tom, iMacros Support
chivracq
Posts: 9374
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: JS Question: How to use ReG Exs to do comparisons

Post by chivracq » Fri Dec 12, 2014 11:16 am

Tom, Tech Support wrote:Hi additional001,

If I understand you correctly, and I'm not sure I follow your description 100%, you would use something like the following:

Code: Select all

var extracted = iimGetLastExtract();

while (extracted.search(/Standby/) != -1)
{
// Code to be performed each time through the loop
}
In this example, the loop will keep executing as long as the extracted data contains the text "Standby".

https://developer.mozilla.org/en-US/doc ... ing/search
Hum..., funny to see TechSupport give an Example using 'iimGetLastExtract()' while we are supposed to use 'iimGetExtract()' instead... :?
- (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...
Tom, Tech Support
Posts: 3601
Joined: Mon May 31, 2010 4:59 pm

Re: JS Question: How to use ReG Exs to do comparisons

Post by Tom, Tech Support » Fri Dec 12, 2014 11:35 am

chivracq wrote:Hum..., funny to see TechSupport give an Example using 'iimGetLastExtract()' while we are supposed to use 'iimGetExtract()' instead... :?
Good catch! The new name iimGetExtract was not available in the iMacros for Firefox Javascript scripting interface at the same time as it was in iMacros Standard/Enterprise editions, so I got used to sticking with iimGetLastExtract when using iMacros-FX.

I've updated the code sample in my original post.
Regards,

Tom, iMacros Support
chivracq
Posts: 9374
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: JS Question: How to use ReG Exs to do comparisons

Post by chivracq » Fri Dec 12, 2014 12:00 pm

Tom, Tech Support wrote:
chivracq wrote:Hum..., funny to see TechSupport give an Example using 'iimGetLastExtract()' while we are supposed to use 'iimGetExtract()' instead... :?
Good catch! The new name iimGetExtract was not available in the iMacros for Firefox Javascript scripting interface at the same time as it was in iMacros Standard/Enterprise editions, so I got used to sticking with iimGetLastExtract when using iMacros-FX.

I've updated the code sample in my original post.
Ah OK, I didn't know there was a difference in time for the introduction/replacement of/with 'iimGetExtract()', I still use regularly 'iimGetLastExtract()' myself, so I meant my Reply as a "gentle" Joke..., and using "iimGetLastExtract" for searching the Forum (for Examples) will still yield far more relevant Hits than using "iimGetExtract"...

BTW, sbd started a Thread quite recently (in the last 2 weeks maybe) about some Differences in Behaviour and Results between the 2 Functions and TechSupport never jumped into the Thread, I think... :idea:
=> Found it...! (Initiated by the same 'Additional001'):
- iimGetExtract vrs iimGetLastExtract: NOT the same!
- (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...
additional001
Posts: 175
Joined: Sun Jul 06, 2008 3:24 am

Re: JS Question: How to use ReG Exs to do comparisons

Post by additional001 » Wed Dec 17, 2014 12:53 pm

Tom, Tech Support wrote:Hi additional001,

If I understand you correctly, and I'm not sure I follow your description 100%, you would use something like the following:

Code: Select all

var extracted = iimGetExtract();

while (extracted.search(/Standby/) != -1)
{
// Code to be performed each time through the loop
}
Updated 2014-12-12: Changed iimGetLastExtract to iimGetExtract.

In this example, the loop will keep executing as long as the extracted data contains the text "Standby".

https://developer.mozilla.org/en-US/doc ... ing/search

Thanks TS Tom this looks exactly like I was looking for. I will test it out as soon as I get a chance.
Post Reply