André
André

Reputation: 103

RegeX in PHP to capture string

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

Answers (2)

Toto
Toto

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

gribvirus74
gribvirus74

Reputation: 765

Use positive lookbehind for each letter:

(?<=v=)\d+
(?<=k=)\d+
(?<=t=)\d+

Upvotes: 0

Related Questions