Regex -匹配大写,特定字符后的简单字符串

时间:2021-08-03 20:07:08

I have following string :

我有以下字符串:

step_User_Save_action_Details

I checking capital or simple letter follows after each underscore symbol, but not all capital..

我在每个下划线的符号后面都要检查大写字母或简单字母,但不是所有的大写字母。

Example:

例子:

step_User_Save_Action_Details - Should return False

step_User_Save_Action_Details -返回False。

step_user_save_Action_Details - Should return True

step_user_save_Action_Details——应该返回True

step_user_save_action_details - Should return True

step_user_save_action_details——应该返回True

try with this but seems to be its not the catching it

试试这个,但似乎并不是你想要的

\bstep(?:_[a-z][a-zA-Z]*)+\b

2 个解决方案

#1


3  

You can use a negative lookahead based regex:

您可以使用基于负面前瞻的regex:

/\bstep(?!(?:_[A-Z][a-zA-Z]*)+\b)(?:_[a-zA-Z]+)+\b/

RegEx Demo

RegEx演示

(?!(?:_[A-Z][a-zA-Z]*)+\b) is a negative lookahead that will fail the match if underscore are all immediately followed by a capital letters.

(?!) (?:_[a-z][a- za -z]*)+\b)是一个负面的前视,如果下划线后面紧跟着一个大写字母,就会导致失败。

#2


0  

Am I missing something? Can't you just use

我遗漏了什么东西?你不能用吗

/_[a-z]/

(Match any string that contains a lowercase letter after an underscore).

(匹配任何在下划线后包含小写字母的字符串)。

#1


3  

You can use a negative lookahead based regex:

您可以使用基于负面前瞻的regex:

/\bstep(?!(?:_[A-Z][a-zA-Z]*)+\b)(?:_[a-zA-Z]+)+\b/

RegEx Demo

RegEx演示

(?!(?:_[A-Z][a-zA-Z]*)+\b) is a negative lookahead that will fail the match if underscore are all immediately followed by a capital letters.

(?!) (?:_[a-z][a- za -z]*)+\b)是一个负面的前视,如果下划线后面紧跟着一个大写字母,就会导致失败。

#2


0  

Am I missing something? Can't you just use

我遗漏了什么东西?你不能用吗

/_[a-z]/

(Match any string that contains a lowercase letter after an underscore).

(匹配任何在下划线后包含小写字母的字符串)。