Reputation: 41
Example code:
<?php
$html = <<< html
<p><a href="http://www.google.com" title="10">google.com</a></p>
<p><a href="http://www.cade.com" title="11">cade.com</a></p>
html;
echo preg_replace('#<p><a href\="([^>]+)" title="([^>]+)">([^>]+)</a></p>#','<p>$1 - $2</p>',$html);
?>
It works fine but i would like to know what [^>]
means. I know that
+
= 1 or more;()
= subpatterns;But I don't know about ^>
Upvotes: 3
Views: 273
Reputation: 360
You have it in the PHP documentation for PCRE regex syntax
First, you have a list of meta-characters. You can check there to find the meaning of characters in regexes.
Concerning your question we find that:
So, [^>] is any character that isn't >
Upvotes: 0
Reputation: 838796
It means any character apart from >
.
(Side note: it is not usually a good idea to use regex to parse HTML.)
Upvotes: 1
Reputation:
^
, when placed at the start of a character class ([
) means any character EXCEPT what's in the class.
In your code, that would mean it would match any character except >
.
Upvotes: 2
Reputation: 1039228
It means that it should match any other character than >
. It also means that the person that wrote this code and tried to parse HTML with regex didn't read the Bible and will very soon regret it.
Upvotes: 1