正则表达式和PHP-如何匹配此字符串?
我有这个字符串:正则表达式和PHP-如何匹配此字符串?,php,regex,Php,Regex,我有这个字符串: First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online: 字符串的制作方式如下: 字符串的第一部分(点) 第二部分(冒号) 第二部分(分号) 第三部分(冒号) 第四部分 4位数字(点) 在线提供(冒号) 如何使用正则表达式在数组中拆分此字符串 谢谢。您可能想要以下产品: $array = preg_split('/\s*[:
First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:
字符串的制作方式如下:
- 字符串的第一部分(点)
- 第二部分(冒号)
- 第二部分(分号)
- 第三部分(冒号)
- 第四部分
- 4位数字(点)
- 在线提供(冒号)
谢谢。您可能想要以下产品:
$array = preg_split('/\s*[:;.]\s*/', $str);
甚至:
$array = preg_split('/\s*[:;.]\s*/', $str, -1, PREG_SPLIT_NO_EMPTY);
产出:
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
)
希望它能帮助您。使用:
([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
“双点”被称为冒号,非常感谢斯科特,他将立即改变这一点。对不起,我的英语:)而“点”被称为句号。好主意,但是如果我在第一部分或第二部分中有一些其他分号呢……谢谢,但这是为了接近我的示例。我需要匹配第一部分和第二部分中的任何内容etc@Milos-我相信它可以匹配任何东西。你怎么会有相反的想法?
First part of string
Second part one
Second part two
Third part
Fourth part
2014
Available online