Greetings. I've tried about 8 different methods of getting this done and am stumped. I need ideas.
I need code to walk thru a hash, comparing each element against a string in case insensitive fashion.
If the string is found to be a substring of any of the elements, the code should return 2 items: the hash's key and the rest of the passed string AFTER the matched text.
The passed string in my case is from the body of an email. I pass each line of the body, compare against this hash, and if a match is found I continue processing. The body MIGHT contain plain-text email content or html content, so funky characters need to be handled/ignored properly. (I do process the HTML emails to strip them, but some odd things slip through sometimes.)
The hash is in the format below:
aMap = {
:matchkey1 => ['label1:', 'label1-', 'label_one:', 'FIRST LINE'],
:matchkey2 => ['label2:', 'lable2-', 'lable_two:', 'EXTRA LINE 1:']
...
}
Here's an example email I might pass to the code to compare against this hash:
"Hi. This is a friendly email from somewhere on the planet.
You've received the following information as requested:
lable1: XYZ Company
EXTRA LINE 1: Joe Smith
That is all. We hope you've enjoyed this fictitious email."
The code should pass each line, ignoring those that have no matches in our hash (lines 1,2,5 in this example).
We should get 2 matches (lines 3,4) that would return the following from the code:
line 3 would return: :matchkey1 and 'XYZ Company'
line 4 would return: :matchkey2 and 'Joe Smith'
Andrew