繁体   English   中英

添加到preg_match_all模式

[英]Add to pattern for preg_match_all

我正在使用以下模式,该模式基本上从字符串之外的字符串中剥离所有内容,该字符串不是以货币符号开头的数字:

$pattern = '/\p{Sc}\s*\d{1,3}(?:,\d{3})*(?:\.\d+)?/u';

但是,由于我要匹配的字符串可以是html源代码,因此这并不完美,因为英国的网站并不总是使用“£”作为值,它们可能会使用£ £

A price might be listed as £10.00 or £10.00 or £10.00

所以我要问的是,使用p{Sc} /u时是否可以将它们添加到混合中

是的,使用包含所有字符类的字符类。

[\p{Sc}\p{...}\p{...}]

编辑:

您可以使用html_entity_decode将字符串中的实体转换为相关字符,然后再使用正则表达式。

$string = html_entity_decode("A price might be listed as £10.00 or £10.00 or £10.00");
$pattern = '/\p{Sc}\s*\d{1,3}(?:,\d{3})*(?:\.\d+)?/u';
$matches = [];
preg_match_all($pattern, $string, $matches);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM