Reputation: 103
How do I get the following values in Regex from the following string
<tr><td>4 <td><b><a href="number.php?v=41a&k=53&t=102">3</a></b>
v = 41
k = 45
t = 102
I wanted only the number of each segment (v k t)
I tried this and got only one at a time
v=\d+
Upvotes: 0
Views: 28
Reputation: 91385
If your input string is really as simple as you said, you could use preg_match_all:
$str = '<tr><td>4 <td><b><a href="number.php?v=41a&k=53&t=102">3</a></b>';
preg_match_all('/(?<=[vkt]=)\d+/', $str, $m);
print_r($m[0]);
Output:
Array
(
[0] => 41
[1] => 53
[2] => 102
)
Upvotes: 1
Reputation: 765
Use positive lookbehind for each letter:
(?<=v=)\d+
(?<=k=)\d+
(?<=t=)\d+
Upvotes: 0