I would like to filter a username from an xml file. The xml file looks like <player id="123456" name="somename" alliance="123"/>. Now I tried the following regex: preg_match("/name=\"(.*)\"/"). But somehow although I have put the \" behind the star symbol, it seems like my regex does not stop at the first " but at the third. This is what I get: somename" alliance="123
What is the reason for this?
I would like to filter a username from an xml file. The xml file
Share
.*is greedy, it will match as many characters as it can so it will not stop until just before the very last"in your string. Change it to.*?and it should only match until the next", since the?makes the repetition lazy instead of greedy.Take a look at the “Laziness instead of Greediness” section on this regex reference page.