Regex inverse matching on specific string?

后端 未结 2 389
北荒
北荒 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. ;)

提交回复
热议问题