[英]Regex and PHP - how to match this string?
I have this string:我有这个字符串:
First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:
The string is made in this way:字符串是这样制作的:
How it is possible to split this string in an array with as described, using regex?如何使用正则表达式将这个字符串拆分为数组中的描述?
Thank you.谢谢你。
You probably want something like:你可能想要这样的东西:
$array = preg_split('/\s*[:;.]\s*/', $str);
or even:甚至:
$array = preg_split('/\s*[:;.]\s*/', $str, -1, PREG_SPLIT_NO_EMPTY);
$string = "First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:";
preg_match("/(.+?)\.(.+?):(.+?);(.+?):(.+?)(\d{4})\.(.+?):/",$string,$m);
print_r($m);
outputs:输出:
Array
(
[0] => First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:
[1] => First part of string
[2] => Second part one
[3] => Second part two
[4] => Third part
[5] => Fourth part
[6] => 2014
[7] => Available online
)
Hope it'd help you.希望对你有帮助。
Using:使用:
([a-zA-Z ]+)\. ([a-zA-Z ]+): ([a-zA-Z ]+); ([a-zA-Z ]+): ([a-zA-Z ]+)([0-9]{4})\. ([a-zA-Z ]+):
Results in:结果是:
First part of string
Second part one
Second part two
Third part
Fourth part
2014
Available online
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.