Click to See Complete Forum and Search --> : regex question
lulzoralot
May 3rd, 2010, 03:09 PM
Hey I need need to extract numerical value between \" and \"
So string is like
$a= '\"123\"';
thanks.
SambaNeko
May 3rd, 2010, 03:29 PM
<?php
$a= '\"123\"';
$pattern = '/[0-9]+/';
preg_match($pattern, $a, $matches);
print_r($matches);
?>
lulzoralot
May 3rd, 2010, 03:43 PM
Thanks.
What if i want to get numerical value between # and # or between [ and ]?
thanks for help by the way....
visualAd
May 3rd, 2010, 03:45 PM
<?php
$a= '\"123\"';
$pattern = '/[0-9]+/';
preg_match($pattern, $a, $matches);
print_r($matches);
?>
While that would work, you are better off looking for the entire string and then pulling the numbers out as a subgroup using brackets.
/\\"([0-9]+)\\\"/
$matches[1] would contain the number.
lulzoralot
May 3rd, 2010, 04:01 PM
While that would work, you are better off looking for the entire string and then pulling the numbers out as a subgroup using brackets.
/\\"([0-9]+)\\\"/
$matches[1] would contain the number.
that works better...thanks man.Will report how it goes in final product...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.