Reputation: 29
I am trying get this number which is between tags << >>
333333
from
string = "my subject <<my-support-id=333333>>"
Can you give any advise as I am not getting anywhere
I am trying to get this using preg_match
function in php.
Upvotes: 0
Views: 57
Reputation: 34416
You could do this -
$string = "my subject <<my-support-id=333333>>";
$pattern = '/\d+/';
preg_match($pattern, $string, $matches);
print_r($matches);
And the output would be Array ( [0] => 333333 )
Upvotes: 0
Reputation: 26667
How about the regex
/<<[^\d]+(\d+)>>/
[^\d]+
Negated character class. would match anything other than digits, \d
(\d+)
Capture group 1 will contain the digits within the << >>
Test
preg_match("/<<[^\d]+(\d+)>>/", "my subject <<my-support-id=333333>>",$matches);
print_r($matches[1]);
=> 333333
OR
/<<[^=]+=(\d+)>>/
Test
preg_match ( "/<<[^=]+=(\d+)>>/", "my subject <<my-support-id=333333>>",$matches);
print_r($matches[1]);
=> 333333
Upvotes: 2
Reputation: 499
Try this:
preg_match_all('/\=([0-9]+)>/','my subject <<my-support-id=333333>>', $out, PREG_PATTERN_ORDER);
echo $out[1][0];
Upvotes: 1