我有这个字符串:
First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:
字符串是这样制作的:
如何使用正则表达式将此字符串拆分为数组?
谢谢。
答案 0 :(得分:3)
您可能需要以下内容:
$array = preg_split('/\s*[:;.]\s*/', $str);
甚至:
$array = preg_split('/\s*[:;.]\s*/', $str, -1, PREG_SPLIT_NO_EMPTY);
答案 1 :(得分:-1)
$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);
输出:
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
)
希望它能帮到你。
答案 2 :(得分:-1)
使用:
([a-zA-Z ]+)\. ([a-zA-Z ]+): ([a-zA-Z ]+); ([a-zA-Z ]+): ([a-zA-Z ]+)([0-9]{4})\. ([a-zA-Z ]+):
结果:
First part of string
Second part one
Second part two
Third part
Fourth part
2014
Available online