for example my string is Foo Bar. this string should match the pattern.
if the string is Foo bar. the string should not match.
if the string is Foo Bar Foobar the string should match
if the string is Foo. it should also match.
so far I only have this pattern
(^[A-Z]{1}.*(\s)?$)+
Basically I will only accept a string where each First letter of each word is Uppercase
To check if the first letter of a string is uppercase, call the toUppercase() method to convert the first letter to uppercase and compare it to itself. If the comparison returns true , then the first letter is uppercase.
Example 2: Convert First letter to UpperCase using Regex The regex pattern is /^./ matches the first character of a string. The toUpperCase() method converts the string to uppercase.
Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter. In a character set a ^ character negates the following characters.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
I'd see if your string does NOT match something like this:
/\b[a-z]/
You can try to use this regex:
^(\b[A-Z]\w*\s*)+$
Regex Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With