PHP - 字符串模式匹配
我需要知道是否有任何方法可以在 PHP 中使用正则表达式(或其他方式)执行以下操作
aaBaa BBB ->啊咩BBB
即,仅当大写字母出现在小写字母之前和之后时,我才想在大写字母之前引入空格。
我能想到的最好的就是这样的东西
$string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string);
,但这只会给我类似的东西
aaBaa BBB ->咩咩BB B
提前致谢。
I need to know if there is any way I can do the following using regular expressions (or otherwise) in PHP
aaBaa BBB -> aa Baa BBB
ie, I want to introduce a space before a capital letter only if a Capital letter occurs before and after a small letter.
The best I could come up with was something like this
$string = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $string);
but that would only give me something like
aaBaa BBB -> aa Baa B B B
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
此处:http://rubular.com/r/3xqbuWuiLD
Here: http://rubular.com/r/3xqbuWuiLD