0

I have some HTML and I need to get link and text from the anchor tag.

$pattern = '/href="(.*)".*>(.*)<\/a>/'

I didn't get exact link from above pattern but If I used the following pattern

$pattern = '/href="(.*?)".*>(.*)<\/a>/'

I get the desired result, But I didn't understand what question mark (?) does here and why I don't get result If I am not using the question mark (?).

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Akash Jain
  • 894
  • 2
  • 10
  • 23
  • Please tag the question with your programming language... And you're better off using a [HTML parser](http://htmlparsing.com/) – Mariano Jul 24 '16 at 11:08

1 Answers1

0

The question mark means either one or no occurrence. Without the question mark there should be only one character ("." means any symbol) there. With question mark it could be empty, like href=""

keiv.fly
  • 3,343
  • 4
  • 26
  • 45