Lucas
Lucas

Reputation: 167

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]*]

Upvotes: 2

Views: 312

Answers (2)

anubhava
anubhava

Reputation: 785156

You can use this regex:

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

RegEx Demo

(?:_[A-Z][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.

Upvotes: 5

d0nut
d0nut

Reputation: 2834

You might be able to try something like this:

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

Regex101

Upvotes: 3

Related Questions