简体   繁体   中英

Regex match everything after each character

I have below string pattern

step_User_Save_Action_Details

I want to make sure a capital letter follows after each underscore symbol.

Example:

step_User_Save_Action_Details - Should return true

step_User_save_Action_Details - Should return false

Tried with below pattern but seems to not working...

step[_[A-Z]*]

You can use this regex:

\bstep(?:_[A-Z][A-Za-z]*)+\b

RegEx Demo

(?:_[AZ][A-Za-z]*) makes sure that there is an uppercase letter right after underscore. + quantifier after this non-capturing group will let it match multiple of these underscores in the word.

\\b is there to enforce word boundary before step and after last component.

You might be able to try something like this:

 ^step(_[A-Z][^_]*)*$

Regex101

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM