Why is my regex pattern not working


These are the regex I used
First Name \n(.+)
Last Name \n(.+)
Email \n(.+)
Phone \n(.+)

could anyone point out the mistake I did and suggest a better one that would scrap the data

1 Like

Hi

First, you shouldn’t use spaces, but escaped characters. But I don’t know where you use that, so it might work.
There isn’t must details in your request on what doesn’t work, however you use \n between your label and the searched string. \n is for new line which you don’t have in your case, you just have a space it seems (remove the space in your regex and replace with \s if you’re sure that this will never be empty, otherwise you need additional checks to ensure it’s not empty.

Hope this helps.

Thank you, I added the /s and it worked. I don’t know how to remove space tho cause I am still learning regex.
Thanks for telling me what /n does, it really helped.

Anyways I am facing problems with 2 patterns now, phone and location.

This is the pattern I used for phone
Phone\s(.+)
this is the output
image
how can I cancel the extra one’s? Is it by using “/”, if so how?

similar error with location, the pattern I used is
Location:*\s(.+)

No output showed, this was the input tho
image
what did I do wrong here

Tell them to end the search at the end of the line. So this time you can use \n

Phone\s*(\d*)\s*\n

Location:\*\s*(.*)\s*\n
1 Like

Thanks mate, that worked!

what does the (.*) do tho also \s
thanks again

\s is every kind of spaces (including line breaks, tabs, etc.)
. means every character (except line breaks)
\d is every decimal, so for phone number I replaced your . by \d

One of the quick references on the topic (you find plenty on google): RegEX Cheat Sheet & Quick Reference

To test your expressions: https://regex101.com/

1 Like

You can use this one too, provides simple explanations together with testing features:
Free Online Regular Expression Tester - FreeFormatter.com

2 Likes