|
-
May 3rd, 2010, 03:09 PM
#1
Thread Starter
Lively Member
regex question
Hey I need need to extract numerical value between \" and \"
So string is like
$a= '\"123\"';
thanks.
-
May 3rd, 2010, 03:29 PM
#2
Re: regex question
Code:
<?php
$a= '\"123\"';
$pattern = '/[0-9]+/';
preg_match($pattern, $a, $matches);
print_r($matches);
?>
-
May 3rd, 2010, 03:43 PM
#3
Thread Starter
Lively Member
Re: regex question
Thanks.
What if i want to get numerical value between # and # or between [ and ]?
thanks for help by the way....
-
May 3rd, 2010, 03:45 PM
#4
Re: regex question
 Originally Posted by SambaNeko
Code:
<?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.
-
May 3rd, 2010, 04:01 PM
#5
Thread Starter
Lively Member
Re: regex question
 Originally Posted by visualAd
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|