Ganesh Ganesh - 5 months ago 20
Java Question

regular expression for underscore and space

I am new to

regular expressions
. I want to write a regular expression which will check ,if a string has more than 1 word then that string has a
_
in between them or not . And also , which will check that string has space before it or not
. for example
[space]Education_Qualifcation
,this should check it has space before that and underscore in between words.So,How can i write that?

Answer

If you want to do it by regex, it would be something like

\s[A-Za-z]+_[A-Za-z]+

It matches a space \s, a sequence of at least one (the +) letter (upper or lower case), an underscore _ and another sequence of at least one letter.

See it here at regex101.