gpt4 book ai didi

php - 使用php preg_match(正则表达式)将camelCase单词拆分为单词

转载 作者:IT老高 更新时间:2023-10-28 12:02:14 27 4
gpt4 key购买 nike

我将如何拆分单词:

oneTwoThreeFour

放入一个数组,这样我就可以得到:

one Two Three Four

preg_match ?

我厌倦了这个,但它只是给出了整个词

$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_split 用作:

$arr = preg_split('/(?=[A-Z])/',$str);

See it

我基本上是在大写字母之前分割输入字符串。使用的正则表达式 (?=[A-Z]) 匹配大写字母之前的点。

关于php - 使用php preg_match(正则表达式)将camelCase单词拆分为单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4519739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com