I’m trying to make a regular expression that will select only the first string of two strings.
IE:
hello:howareyou
I want the regex to return only hello.
Similarly, I would want another one to return howareyou, but I should be able to figure that out once I understand the first part.
Thank you!
EDIT:
So far I have tried (?:[^"<:]|"[^"]*"|<[^>]*)* but that merely splits the two.
You could simply use
explode(':', $str), but if you insist on using a regular expression, you can do that as well withpreg_match('/(.+?):(.+)/', $str, $matches)which will return the first part in$matches[1]and the second part in$matches[2].