字符串为
#include <stdio.h>
int
main(void)
{
char c = 0;
printf( "%c\n", c ); //Prints the ASCII character which is NULL.
printf( "%d\n", c ); //Prints the decimal value.
return 0;
我想从这个字符串中提取$ 11.04。请帮我解决这个问题 使用PHP正则表达式。
答案 0 :(得分:0)
这将起作用:,假设源字符串实际包含<b>
:
<?php
$s = '--------<b>Deal Price: $11.04</b>&l-----------';
$m = array();
if (preg_match('#<b>(Deal Price:)\s+(.+)</b>#', $s, $m) == 1) {
if (count($m) > 2) {
echo $m[2];
}
}
?>
答案 1 :(得分:0)
您可以查找$
,然后按
(?<=\$)\d+(?:\.\d+)?
(?<=\$) # look for $ immediately behind
\d+ # at least one digit, possibly more
(?: # followed by a non-capturing group
\.\d+ # a dot and more digits
)? # but made optional
有人可能会争辩说,亚马逊可能会有像$10,000
这样的奖品,这个奖项不会被这个表达所覆盖。因此,您可以使用
(?<=\$)\d+[\d,]*(?:\.\d+)?