Looking for a regexp which match with characters starting by an uppercase and finish by lowercase or a number For example :
Foo2B => Foo, 2, B
I find ^([A-Z][a-z]*|[0-9]*)
but it return Foo, 2B
Looking for a regexp which match with characters starting by an uppercase and finish by lowercase or a number For example :
Foo2B => Foo, 2, B
I find ^([A-Z][a-z]*|[0-9]*)
but it return Foo, 2B
The |
character means "OR", so your regex is actually matching two different things - either [A-Z][a-z]*
OR [0-9]*
at the beginning of a string.
What you're looking for is this: ^[A-Z][a-z0-9]*
. This matches a leading uppercase letter, followed by a lowercase letter or number repeated zero or more times.
The regexp was OK I didn't used it well in JavaScript that's why I though the regexp was wrong.
For information
'Foo2B'.split(/([A-Z][a-z]*|[0-9]*)/).filter((elem) => elem !== '')