I’m currently trying to detect emails, phone numbers, and links in a multiline input using Regex. Does anyone have great expressions/patterns to accomplish these? The catch is that the detected text will be in the same input as other random text, not by itself.
I’ve got an solid pattern for detecting emails: ([\w-]+(.[\w-]+)@([a-z0-9-]+(.[a-z0-9-]+)?.[a-z]{2,6}|(\d{1,3}.){3}\d{1,3})(:\d{4})?)
I’ve been using http://regexr.com/ to find these patterns from their community but they don’t seem to be working unless the thing I’m detecting is the only text in the input.
I think solidifying these 3 patterns would be a huge benefit to a large group of Bubblers.
@fayewatson I saw you had a detailed (and quite entertaining) post dealing with Regex. Any ideas here?
Ah! I think I know which post you’re referring to Glad to hear it was entertaining!
I’m not 100% sure but with a single multiline input, I think you would need to have three different expressions for emails, phone numbers and links. Are you saving the values which are extracted into separate fields?
For URLs, I currently use:
(http|ftp|https)://([\w_-]+(?:(?:.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?
This works well! but I don’t think this would work if there isn’t an http or https at the start of the URL. Are you looking to extract links in the format of just “google.com” as well?
I haven’t tested this for phone numbers thoroughly, but I think this extracts it correctly, for a number of different phone formats:
(?:+?(\d{1,3}))?[- (](\d{3})[- )](\d{3})[- ]*(\d{4})(?: *x(\d+))?\b
I just sent this tip out in a newsletter this past week! Here’s the pattern you want that will get all three below. You can see that they’re separated by a pipe character. It’s long but gets the job done.
Hm, working for me unless I’m misunderstanding your goal. Your expression works as well as “Multiline’s value:extract with Regex:first item is not empty”
Hmm, I think I may have copy+pasted the wrong regex for phone validation previously! If anyone is looking for one just for phone numbers, this pattern seems to work:
Loved your regex for extracting URLs… but in my case the JSON I’m receiving contains 2 URLs… I just want the first one… How would your regex look like? can you help me?
Somehow as I tested it now the Regex provided by you was not capturing phone and email inputs, although I was entering it into “Multiline’s value:extract with Regex:first item is not empty”. Does it still working for you?
For those who have the same issue, I want to share Regex that helps identifying phone numbers:
I tried this:
Multiline’s value:extract with Regex:first item is not empty
with the Regex:
(?!:\A|\s)(?!(\d{1,6}\s+\D)|((\d{1,2}\s+){2,2}))(((+\d{1,3})|((+\d{1,3})))\s*)?((\d{1,6})|((\d{1,6})))/?(([ -.]?)\d{1,5}){1,5}((\s*(#|x|(ext)).?\s*)\d{1,5})?(?!:(\Z|\w|\b\s))
It doesn’t work. Is there anything yet this i need or missing? I am new to bubble!