dqe9657 2013-04-02 23:31
浏览 71
已采纳

PHP中的正则表达式,用于查找Camel Case中的最后一个upcase字符

I want to match in PHP the last capitalize (http://php.net/manual/en/function.ucfirst.php) character in the string.

To add to the complication I want to ignore everything after a different string, e.g. a sequence of uppercases that not capitalized or in camel case style.

Here follow some examples of what should and shouldnt match

Matches:

Foobar => Expected char: F
fooBar  => Expected char: B
A_fooBar  => Expected char: B
fooBAR => Expected char: B (Most complicated situation)

No matches:

foo A_bar
foobar
foo bar foo bar
foobar /* Comment */

So far I've tried the following regex:

(?!A_)[A-Z](?!((?!/\*).)*\*/)

but with no luck. From Question: the Regexp match any uppercase characters except a particular string (Very similar situation)

@edit

And another regex

/([A-Z])[^A-Z\W]*$/

http://phpfiddle.org/main/code/dyq-3h7

  • 写回答

3条回答 默认 最新

  • dsfs64664 2013-04-02 23:55
    关注

    I believe this matches where appropriate, and will ignore your other examples as well.

    ^\w*?(?<![A-Z_])([A-Z])(?!_)
    

    See this fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?