Hi fylthymcnasty,
I'm glad the code worked well for you. A few hours after I posted that, I thought of a case where that code might fail... or should I say, perhaps not perform as you intended... and your above post just reminded me so here we go...
The above code will match on parial strings... for example, if you scrape "gold" from a website, that's going to be seen as a match... even though what you have in the list is actually "pots of gold". If that is fine and exactly what you want, don't change anything, you're there.
However, if you need or would like to recognize partial matches as being partial... then the code below will do the trick.
I was going to do this without using the RegEx> command... but RegEx> makes this so easy that I can't imagine not using it in this case... however if someone wants to post the solution without using RegEx> then feel free.
In the Message Box lines, I added double quotes " on either side of the displayed variables string_scraped_from_a_website and whole_line_from_string_list to make things more clear for the user.
The code below detects non-matches, perfect matches and partial matches as well... keep an eye on those
Lucky Charms!
Code: Select all
/*
TEXT:
Pink Hearts
Yellow Moons
Orange Stars
Green Clovers
Blue Diamonds
Purple Horseshoes
Red Balloons
Pots of Gold
Rainbows
Hourglasses
*/
Let>filename=C:\my_string_list_one_per_line.txt
LabelToVar>TEXT,values_for_text_file
WriteLn>filename,result,values_for_text_file
//load the entire text file into variable string_list
ReadFile>filename,string_list
//switch all to UPPERCASE in our variable
UpperCase>string_list,string_list
//test 1 - no match
Let>string_scraped_from_a_website=BLUE berries
GoSub>test_the_string_and_display_result
//test 2 - match
Let>string_scraped_from_a_website=green CLOVERS
GoSub>test_the_string_and_display_result
//test 3 - "partial" match
Let>string_scraped_from_a_website=gold
GoSub>test_the_string_and_display_result
SRT>test_the_string_and_display_result
//switch all to UPPERCASE in our test string
UpperCase>string_scraped_from_a_website,string_scraped_from_a_website
Position>string_scraped_from_a_website,string_list,1,StartPos
If>StartPos=0
MDL>Sorry "%string_scraped_from_a_website%" not found in me list
Else
//check if string_scraped_from_a_website matches ENTIRE line in string_list
//its good practice to clear first var in match array prior to every use/re-use
Let>matches_1=
//in regex pattern below, (?m) turns on muli-line mode so we can match to individual "lines" within the var
//[^\x0D\x0A]* will match any non CR or LF chars on either side of our search string
Let>pattern=(?m)^[^\x0D\x0A]*%string_scraped_from_a_website%[^\x0D\x0A]*$
RegEx>pattern,string_list,0,matches,num,0
Let>whole_line_from_string_list=matches_1
If>string_scraped_from_a_website=whole_line_from_string_list
MDL>"%string_scraped_from_a_website%" is in me list... oh oh... they're after me Lucky Charms!
Else
MDL>"%string_scraped_from_a_website%" is *PARTIALLY* in me list... the full line item in me list is actually "%whole_line_from_string_list%" but shhhh, don't tell them... I think they're after me Lucky Charms!
EndIf
EndIf
End>test_the_string_and_display_result