Regex inverse matching on specific string?

后端 未结 2 390
北荒
北荒 2021-01-19 23:16

I would like to match the following

  • com.my.company.moduleA.MyClassName
  • com.my.company.moduleB.MyClassName
  • c
相关标签:
2条回答
  • 2021-01-19 23:52

    Perhaps a regex is not the clearest way to write this.

    if (className.startsWith("com.my.company.") 
        && !className.startsWith("com.my.company.core.")) {
    
    }
    

    This is fair clear what it does, and you might find it is faster. ;)

    0 讨论(0)
  • 2021-01-19 23:54

    You can use the following regex:

    ^com\\.my\\.company\\.(?!core).+?\\.MyClassName$
    
    0 讨论(0)
提交回复
热议问题