Hey,
I’m trying to become better at Regex. Can someone please help me get “Company ABC” in this string:
Company Name: Company ABC
Address: Fake Address
Hey,
I’m trying to become better at Regex. Can someone please help me get “Company ABC” in this string:
Company Name: Company ABC
Address: Fake Address
Use regex (?<=Company Name: ).*
.
To get better with regexes, visit rexegg.com and test your regular expressions at regex101.com.
Hey thanks for this.
I understand everything until the .* What does the .* do?
The .
means “any character”, whether it be a space, numbers, letters, etc. The *
means “0 or more of the previous indicator”. So in all it means “0 or more of any character”.
ah so after Company name, get any character?
Yes, and this works on a single-line basis. So if your string contains newline characters, it stops before going to the next line.
Great! So what if I wanted a newline as well? Say I wanted “Company ABC DEF Corp” from:
Company Name: Company ABC
DEF Corp
?
Then append \n.*
if you want all lines after that in one match.
Ah great! But what if I just want the next line and not all the lines?
Append \n[^\n]*
instead.