Regex replace

Discussions and Tech Support related to the iMacros Google Chrome extension.

Moderators: Community Moderators, iMacros 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.

Regex replace

by rigsel on Thu Nov 09, 2017 9:24 am

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 9:09 am

Re: Regex replace

by rigsel on Thu Nov 23, 2017 8:29 am

Anyone?
I'm using iMacros for Chrome, version 8.4.4 :D
rigsel
 
Posts: 3
Joined: Thu Nov 09, 2017 9:09 am

Re: Regex replace

by chivracq on Thu Nov 23, 2017 9:58 am

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)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: 6479
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Chrome

Who is online

Users browsing this forum: No registered users and 2 guests

-->