0

Working code

But the amount of line breaks can be random,

<\/time>\s\s\s<a href=\"(.*?)\" 

If the amount of lines/spaces are not known, in the example there are 3 line breaks so i entered 3 of them.

\s

What should I enter?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    `\s*` should work, what's the problem? – Aniket Sahrawat Mar 18 '18 at 03:51
  • 1
    Why doesn’t `\s*` work for you? – Josh Withee Mar 18 '18 at 03:54
  • What about just using a parser? `\s*` would work as demonstrated here, https://regex101.com/r/1OZDHw/3. – chris85 Mar 18 '18 at 03:59
  • The double quote (`"`) is not a meta-character in `regex`, it doesn't need to be escaped. If your `regex` uses `/`, use a different [delimiter](http://php.net/manual/en/regexp.reference.delimiters.php) (f.e. `#`) and you can use `/` unescaped too. – axiac Mar 18 '18 at 09:31

1 Answers1

0

I would try something like:

preg_match('/<\/time>\s{0,}<a href=\"(.*?)\" /', $value);

When I do this using curl to get a response from a web page one of the first things I do is run the response through a preg_replace and remove any extra spaces from the string. Then you know that you will always be dealing with one space between any two characters. Like this:

$value = preg_replace('/\s{1,}/', ' ', $value);
Joseph_J
  • 3,654
  • 2
  • 13
  • 22