普通网友 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

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?