[英]Regex and PHP - how to match this string?
我有這個字符串:
First part of string. Second part one: Second part two; Third part: Fourth part 2014. Available online:
字符串是這樣制作的:
如何使用正則表達式將這個字符串拆分為數組中的描述?
謝謝你。
你可能想要這樣的東西:
$array = preg_split('/\s*[:;.]\s*/', $str);
甚至:
$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);
輸出:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.