How to strip everything except content in the bracket?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
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
imacrobest
Posts: 13
Joined: Fri Aug 19, 2016 2:03 pm

How to strip everything except content in the bracket?

Post by imacrobest » Mon Jul 23, 2018 10:42 am

Hi,

I have this texts:

This is a test (HELLO) abcefg 21/05/2018

How do I remove everything and only extract the word HELLO
?
Thanks

iMacros chrome Extension: 10.0.2
iMacros_for_Chrome
Windows 10 64
Chrome Version 67.0.3396.99 (Official Build) (64-bit)
chivracq
Posts: 8193
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to strip everything except content in the bracket?

Post by chivracq » Mon Jul 23, 2018 11:51 am

imacrobest wrote:Hi,

I have this texts:

This is a test (HELLO) abcefg 21/05/2018

How do I remove everything and only extract the word HELLO
?
Thanks

Code: Select all

iMacros chrome Extension: 10.0.2
iMacros_for_Chrome
Windows 10 64
Chrome Version 67.0.3396.99 (Official Build) (64-bit)
Yep..., "basic" Use of 'EVAL()' in this Case, using 'split()' x2 is probably the easiest...
If you search my Posts on "eval + double + split", you will probably find a few dozens of Examples... :idea:
Can be done with 'REGEXP' as well, but I don't like 'REGEXP', ah-ah...!
- (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...
imacrobest
Posts: 13
Joined: Fri Aug 19, 2016 2:03 pm

Re: How to strip everything except content in the bracket?

Post by imacrobest » Mon Jul 23, 2018 12:08 pm

I did find a solution but it's abit messy but was hoping for a cleaner solution without me doing multiple stripping. My current solution is working but abit too long..


'Strip unwanted texts
SET !VAR1 EVAL("var str='{{!EXTRACT}}'; var res = str.replace(/This/gi,\"\"); res;")
SET !VAR2 EVAL("var str='{{!VAR1}}'; var res = str.replace(/is/gi,\"\"); res;")
etc..

SET !VAR3 EVAL("'{{!VAR2}}'.replace(/[\\(\\)]/g, '');")


'Doing some Splitting to clean up
SET !VAR4 eval("\"{{!VAR3}}\".match(/^\\s*\\S+/)[0]")
SET !VAR5 eval("\"{{!VAR3}}\".match(/^\\s*\\S+\\s+(.+)\\s*$/)[1]")


chivracq wrote:
imacrobest wrote:Hi,

I have this texts:

This is a test (HELLO) abcefg 21/05/2018

How do I remove everything and only extract the word HELLO
?
Thanks

Code: Select all

iMacros chrome Extension: 10.0.2
iMacros_for_Chrome
Windows 10 64
Chrome Version 67.0.3396.99 (Official Build) (64-bit)
Yep..., "basic" Use of 'EVAL()' in this Case, using 'split()' x2 is probably the easiest...
If you search my Posts on "eval + double + split", you will probably find a few dozens of Examples... :idea:
Can be done with 'REGEXP' as well, but I don't like 'REGEXP', ah-ah...!
chivracq
Posts: 8193
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to strip everything except content in the bracket?

Post by chivracq » Mon Jul 23, 2018 12:24 pm

imacrobest wrote:I did find a solution but it's abit messy but was hoping for a cleaner solution without me doing multiple stripping. My current solution is working but abit too long..

Code: Select all

'Strip unwanted texts
SET !VAR1 EVAL("var str='{{!EXTRACT}}'; var res = str.replace(/This/gi,\"\"); res;")
SET !VAR2 EVAL("var str='{{!VAR1}}'; var res = str.replace(/is/gi,\"\"); res;")
etc..

SET !VAR3 EVAL("'{{!VAR2}}'.replace(/[\\(\\)]/g, '');")

'Doing some Splitting to clean up
SET !VAR4 eval("\"{{!VAR3}}\".match(/^\\s*\\S+/)[0]")
SET !VAR5 eval("\"{{!VAR3}}\".match(/^\\s*\\S+\\s+(.+)\\s*$/)[1]")
Yeah..., that's what I mean with 'REGEXP' that I find difficult to use and a bit "messy" indeed, while 'EVAL()' + 'split()' x2 "does the Job" in one simple Line...:

Code: Select all

'Extracted: "This is a test (HELLO) abcefg 21/05/2018" => Keep "HELLO":
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('('); y=x[1].split(')'); z=y[0]; z;")
- (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...
Post Reply