0

as you know when you write a regex code and you want it to go until something(matches) in a page source in php , it goes and matches the last one of that character or match in the page , and here is the problem i need to match it just to the first character and avoid it to go to the last one or even the second one and here is my piece of regex code

#<a href="/lyrics/[\s\S]{1,}/[\s\S]{1,}.html#

i need it to match the very first .html in the page just in the href in the a tag , but it matches the last .html in the page and puts it into the 0 section of my array tnx for helping ;)

TheDevWay
  • 1,363
  • 1
  • 16
  • 45
  • 2
    You probably want to read http://stackoverflow.com/questions/3075130/difference-between-and-for-regex – HamZa Nov 30 '14 at 22:16

1 Answers1

1

I need it to match the very first .html in the page just in the href in the a tag ...

Unless I am misunderstanding something, have you considered using DOM instead of regex?

$doc = DOMDocument::loadHTML('
    <a href="/lyrics/foo/foo.html">...</a>
    <a href="/lyrics/bar/bar.html">...</a>
    <a href="/lyrics/foobar/foobar.html">...</a>
    <a href="/lyrics/foobaz/foobaz.html">...</a>
    <a href="/lyrics/baz/baz.html">...</a>
');

$tag = $doc->getElementsByTagName('a')->item(0);
echo $tag->getAttribute('href'); //=> "/lyrics/foo/foo.html"
hwnd
  • 69,796
  • 4
  • 95
  • 132
  • im not familier with dom , but in this source when i match the regex , i have the link in the href into the a tag but it doesnt end in the first .html in the page , and when i say until .html in the regex , it goes and matches the last .html in the page's source code , and i would like to match the first one which is the end of the link and start the second one and again match with the first .html after that,and with this i want all the links matches in an array , but when i do it with this regex,it just matches to the last .html in the page and puts the entire match in the 0 part of the array – TheDevWay Dec 01 '14 at 17:39