使用php preg_match(正则表达式)将camelCase单词拆分为单词 [英] Split camelCase word into words with php preg_match (Regular Expression)
本文介绍了使用php preg_match(正则表达式)将camelCase单词拆分为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何拆分单词:
oneTwoThreeFour
放入一个数组,这样我就可以得到:
into an array so that I can get:
one Two Three Four
带有preg_match
吗?
我很累,但这只是整个单词
I tired this but it just gives the whole word
$words = preg_match("/[a-zA-Z]*(?:[a-z][a-zA-Z]*[A-Z]|[A-Z][a-zA-Z]*[a-z])[a-zA-Z]*\b/", $string, $matches)`;
推荐答案
您也可以将preg_match_all
用作:
preg_match_all('/((?:^|[A-Z])[a-z]+)/',$str,$matches);
说明:
( - Start of capturing parenthesis.
(?: - Start of non-capturing parenthesis.
^ - Start anchor.
| - Alternation.
[A-Z] - Any one capital letter.
) - End of non-capturing parenthesis.
[a-z]+ - one ore more lowercase letter.
) - End of capturing parenthesis.
这篇关于使用php preg_match(正则表达式)将camelCase单词拆分为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文