I'm trying to pull data of Shipping info from a string containing line breaks. The shipping info maybe between 3 and 5 lines. Here's a few examples:
/* Just need from here */
Ship NEXT DAY PM to:
John Doe
Address Street
Sweet, NC 55555
/* to here */
Email: john@doe.net
Phone: 555-555-555
Ship NEXT DAY AM to:
John Doe
Address Street
Apt. 555
Sweet, NC 55555
Email: john@doe.net
Phone: 555-555-555
Ship NEXT DAY PM to:
John Doe
c/o Jane Doe
Address Street
Apt. 555
Sweet, NC 55555
Email: john@doe.net
Phone: 555-555-555
UPDATE
I finally figured out a solution for the regex. Also one was mentioned in comments that seems to work well. Not sure which would be better based on any "why" but here they are:
Ship (.)+ to\:((\n)(.)+){1,5}
Ship (.)+ to\:[\s\S]*?(?=\nEmail)
Now I've got a whole new issue. Turns out, MySQL REGEXP does not function as I expected (which I would have known had I bothered to read rather than skim API). So Now I'm trying to pull what I just regexed out of a substring IF it exist. The IF part I got, I simply use the REGEX to check if Ship To is found and if not NULL then start on substring extraction. The Substring extraction is where I'm stuck now as it's proving rather tedious in using LOCATE
in multiple combinations to try and get exact character position. Anyone know a quick and easy way? I'll post what I'm working on as soon as I don't get an ERROR, lol.
So far working the following into If statement:
MID(`Notes`, (LOCATE(' to:\n', `Notes`) + 5), (LOCATE('\n\nEmail:', `Notes`) - LOCATE(' to:\n', `Notes`) - 5)) as ShipAddress