Regex replace

Discussions and Tech Support specific to the iMacros for Chrome extension.
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
rigsel
Posts: 3
Joined: Thu Nov 09, 2017 4:09 pm

Regex replace

Post by rigsel » Thu Nov 09, 2017 4:24 pm

Hi guys,

How can I do a Regex replace, so a text replacement using Regular Expression?

I guess I need to use EVAL and javascript REPLACE but it only works with normal text, not with regex.
Here's my test code to remove the "22":

Code: Select all

SET !VAR1 Regex-22-Replace
PROMPT {{!VAR1}}
SET !VAR2 EVAL("var str=\"{{!VAR1}}\"; var x=str.replace(\"\\d+\", \"\"); x;")
PROMPT {{!VAR2}}
While the non-regex replace works fine:

Code: Select all

SET !VAR2 EVAL("var str=\"{{!VAR1}}\"; var x=str.replace(\"22\", \"\"); x;")
rigsel
Posts: 3
Joined: Thu Nov 09, 2017 4:09 pm

Re: Regex replace

Post by rigsel » Thu Nov 23, 2017 3:29 pm

Anyone?
I'm using iMacros for Chrome, version 8.4.4 :D
chivracq
Posts: 9311
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Regex replace

Post by chivracq » Thu Nov 23, 2017 4:58 pm

rigsel wrote:Hi guys,

How can I do a Regex replace, so a text replacement using Regular Expression?

I guess I need to use EVAL and javascript REPLACE but it only works with normal text, not with regex.
Here's my test code to remove the "22":

Code: Select all

SET !VAR1 Regex-22-Replace
PROMPT {{!VAR1}}
SET !VAR2 EVAL("var str=\"{{!VAR1}}\"; var x=str.replace(\"\\d+\", \"\"); x;")
PROMPT {{!VAR2}}
While the non-regex replace works fine:

Code: Select all

SET !VAR2 EVAL("var str=\"{{!VAR1}}\"; var x=str.replace(\"22\", \"\"); x;")
rigsel wrote:Anyone?
I'm using iMacros for Chrome, version 8.4.4 :D
Aaaahhh...!, that's already "better", iMacros Version finally mentioned..., but CR Version and OS are still missing for me to have a look...
=> FCIM...! :mrgreen: (Read my Sig...)

=> Applies to your "other" Thread as well where I already asked you, and which is still waiting for some Follow-up from your Side, oops...! :roll:
Sorry, but you should make some little "Effort" to start using the Forum "a bit correctly" if you want me to help you, that would "speed up the Process" if you are really looking for a Solution... :idea:

And selecting the correct Sub-Forum each time you open a Thread belongs as well to "using the Forum a bit correctly", the 'iMacros for CR' Sub-Forum is meant for Threads specific to iMacros for CR only and Scripts that work in other Browsers but fail in CR... (Correct Sub-Forum would have been the 'General' one..., but no need to duplicate now...)
Even if hum..., you had searched the Forum for your other Thread and managed to find a similar/related Thread, that was a "very correct Use of the Forum", ah-ah...! :D
- (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...
Post Reply