普通网友 2014-12-08 05:51
浏览 180
已采纳

在一个正则表达式中组合多个正则表达式组

I m trying to combine multiple regex pattern groups into a single regex pattern

Demo Here

\b 
(?<CASE_UPPER>[[:upper:]]+)
(?<CASE_MIXED>[A-z]*[A-Z][A-z]*+)
(?<CASE_INITIALCAPS>[A-Z][a-z]+[A-Z]*+)
(?<PHRASE>[A-Z][\w-]*\s+[A-Z][\w-]*+)
\b

For This Text block:

I am testing to see if this works for UPPERCASE, InitialCase and mixedCase which of course is also mIxedcase. Firstword initial case should not be matched. FirstWordMixed case should be. UPPERCASE first word should be. And of course phrases that combine any combination of UPPER mixEd Initicase should be pulled as a phrase not a word which could be of course Initcase1 Initcase2 Initcase3. Finally it needs to match all sorto of Associations such as Association of First Words, Last Word for Association, Middle Word Association for Words.

It works with Single group but not working with all together.I don't know if I m doing it in a right way! Any Help would be appreciated.

  • 写回答

1条回答 默认 最新

  • drbvm26000 2014-12-08 06:27
    关注

    Based on what I understood

    You can use alternations | to combine the different regex

    \b 
    ((?<CASE_UPPER>[[:upper:]]+)|
    (?<CASE_INITIALCAPS>[A-Z][a-z]+[A-Z]*+)|
    (?<CASE_MIXED>[A-z]*[A-Z][A-z]*+)|
    (?<PHRASE>[A-Z][\w-]*(\s+[A-Z][\w-]*)+))
    \b
    

    Regex Example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码