mizanrobi wrote: ↑Thu May 14, 2020 5:56 pm
Hi
thanks a lot. I am really sorry to answer after you ask. You have already mentioned me about this FCI before so I should be careful about it, I believe any new thread I create on the forum will mention the FCI at the first hand. Please accept my apology.
s=s.replace(/^\\s*|\\s*$/g, \"\"); the regular expression I am using to trim leading space. when I am extracting data in my csv file it comes with leading space for product title, so I use this regular expression to trim leading space.
Note that this piece of code does not effect on my rest of code means the condition I use does not change result if I remove this regular expression code.
Thank you.
Ah..., OK for the "Trim" Functionality, well then, you could simply use the 'trim()' Method instead...!
Then OK, I did "a little bit" of Testing, you'll get a "long Version", and a "Short Version", ah-ah...!, even if I guess you'll only be interested by the "Short Version", but OK, fair enough...
So OK, I had a "Look" at your proposed 'EVAL()' Statement:
Code: Select all
SET !var7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
... Then hum, OK, so you didn't go at all for the Method I had suggested, even if it works, your Sol/Implementation would indeed be "simpler" than the one I had suggested, even if 'search()' does the same like 'indexOf()' I had mentioned, although I'm not sure 'indexOf()' can use Multiple Args, but they both return an Index, and "-1" if not/none Found which is what your Expression always returns.
And I think also the Syntax you are using for 'search()' is incorrect... (I tried it in my "Long Version" Script, it always returns "-1", I think...) I'm not a JavaScript Guru, but
correct would be:
..., or you can also replace the Single Quotes by Escaped Double Quotes, that should work also, but I always try to use Single Quotes inside 'EVAL()' as they (most of the time) don't need to be Escaped...
Your 'if' Condition will never do anything I think, as I think it is incomplete, 'search()' returns an Index, not a Boolean.
Then I thought, hum interesting, I didn't "know", well never tried, because I never needed the Functionality I guess, that 'split()' could use Multiple Args, hum-hum, good to know... But nope, it doesn't work, ah-ah...!! (It always only uses the 1st Arg, like you found out...)
>>>
Then alright, here is the "Long Version" of the (Debug) Script I used:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=https://forum.imacros.net/viewtopic.php?f=7&t=31007&p=85387#p85387
TAG POS=2 TYPE=DIV ATTR=TXT:mizanrobi<SP>wrote:<SP>↑12/05/2020<SP>-<SP>22:28HiI<SP>am*
SET PROMPT_Debug PROMPT_Debug:<BR><BR>
'SET !EXTRACT "Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET !EXTRACT "Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
ADD PROMPT_Debug EXTRACT:<SP>(,-:)<BR>_{{!EXTRACT}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>
TAG POS=8 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=1 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_12 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
'SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/,\\/gi); x;")
'SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/-\\/gi); x;")
'SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/:\\/gi); x;")
'>
SET Rst_Index_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf(','); x;")
SET Rst_Index_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf('-'); x;")
SET Rst_Index_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(,)<BR>_{{!EXTRACT}}_<BR><BR>VAR1_(,):<BR>_{{!VAR1}}_
ADD PROMPT_Debug <BR>Rst_Search_1:<SP>_{{Rst_Search_1}}_<BR>Rst_Search_12:<SP>_{{Rst_Search_12}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_
ADD PROMPT_Debug <BR>Index_Comma:<SP>_{{Rst_Index_Comma}}_<BR>Index_Dash:<SP>_{{Rst_Index_Dash}}_<BR>Index_Colon:<SP>_{{Rst_Index_Colon}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>
'PAUSE
TAG POS=9 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=2 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_22 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(-)<BR>_{{!EXTRACT}}_<BR><BR>VAR2_(-):<BR>_{{!VAR2}}_
ADD PROMPT_Debug <BR>Rst_Search_2:<SP>_{{Rst_Search_2}}_<BR>Rst_Search_22:<SP>_{{Rst_Search_22}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>
'PAUSE
TAG POS=10 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=3 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_3 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_32 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(:)<BR>_{{!EXTRACT}}_<BR><BR>VAR3_(:):<BR>_{{!VAR3}}_
ADD PROMPT_Debug <BR>Rst_Search_3:<SP>_{{Rst_Search_3}}_<BR>Rst_Search_32:<SP>_{{Rst_Search_32}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_
PROMPT {{PROMPT_Debug}}
... Which returns in the 'PROMPT':
Code: Select all
PROMPT_Debug:
EXTRACT: (,-:)
_Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Split_All: _Telescopic Fishing Rod_
'>>>
EXTRACT: (,)
_Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
VAR1_(,):
_Telescopic Fishing Rod and Reel Combos Full Kit_
Rst_Search_1: _47_
Rst_Search_12: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _47_
Search_Dash: _-1_
Search_Colon: _-1_
Index_Comma: _47_
Index_Dash: _-1_
Index_Colon: _-1_
'>>>
EXTRACT: (-)
_Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
VAR2_(-):
_Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Rst_Search_2: _-1_
Rst_Search_22: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _-1_
Search_Dash: _47_
Search_Colon: _-1_
'>>>
EXTRACT: (:)
_Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
VAR3_(:):
_Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Rst_Search_3: _-1_
Rst_Search_32: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _-1_
Search_Dash: _-1_
Search_Colon: _47_
>>>
And here is the "Short Version", that works thus...:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=https://forum.imacros.net/viewtopic.php?f=7&t=31007&p=85387#p85387
'SET !EXTRACT "Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET !EXTRACT "Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
SET PROMPT_Debug PROMPT_Debug:<BR><BR>
ADD PROMPT_Debug EXTRACT:<SP>(,-:)<BR>_{{!EXTRACT}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
PROMPT {{PROMPT_Debug}}
(Written and Tested on iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)
So it uses 'match()' that apparently returns the first of the 3 Separators, which is then reused for the 'split()'. Fairly simple...!
Some other Solution could have been to use "your" 'search()', but then you need to use 'substring()' or 'substr()' instead of 'split()' like I had suggested...
I expected for the "x" in "y=s.split(x);" to have to specify "x[0]" in case of more than 1 of the 3 Separators to be present in the 'EXTRACT', but apparently, that's not needed, even if it works also with "x[0]" (=> y=s.split(x[0]);), but strangely enough, it doesn't work anymore with "x[1]"... I didn't investigate why as you want the 1st one anyway...
Oh yeah, and if you want to re-add the Trim Functionality, then that would give:
Code: Select all
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.trim(); y=x.match(',|-|:'); z=x.split(y); z[0];")
(Not tested, as the "EXTRACT"('s) I was able to use were already "clean"...)
Alright, see/check/test/confirm if it works for you also, on your "real" Site and with different "Examples", you never posted the URL of the Site, so I couldn't do some "real" Testing on it, and once you are "Happy" with that Solution, I will post it as "Answer" on SOF also...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...