Great stuff here!
I’m fairly decent with basic Regex, but where I struggle with is with an example like below
===
Submission 1
Name: Bryan
Email: test@abc.com
Phone: 012345
===
Submission 2
Name:Bryan2
Phone: 0141231
Normally what I would have done is used a Regex pattern of
Name:(.)\nEmail:(.)\nPhone:(.*)
Which works great for Submission 1, but not Submission 2. Is there a way in regex to treat a string as optional? I.e I’d like Email:(.*) to be an optional match. i.e if not found just skip straight to the next possible match.
Hi Jim,
Gave that a try, but didn’t seem to work
It didn’t match any of the text in the string
This seemed to work for me
Name:(.)\n(Email:(.)\n|)Phone:(.*)
Thanks for pointing me in the right direction Jim!
EDIT: I just realized that Discourse is hiding the * in the first two group brackets. You can notice a difference between the text I pasted and the screenshot
@D-EFFCON
My bad.
I’m usually very good at making sure to use preformatted text for that.
My original text:
Name:(.*?)\n(Email:(.*?)\n|)Phone:(.*)
A better version:
Name:\s*(.*?)\n(Email:\s*(.*?)\n|)Phone:\s*(.*)
3 Likes
When putting in code excursions try to escape any expressions with the code tool.
Code expression
4 Likes