Reputation: 2491
edit: strictly speaking, they are not acronyms but you get what I mean.
I have found this resource very helpful, https://newbedev.com/regex-for-pascalcased-words-aka-camelcased-with-leading-uppercase-letter but what if I need to tweak the lower camel case version to allow a set of initials to be used in the middle of a name. For example, the author provides a regex for lower camel case, [a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?, which would match the following words:
xmlHttpRequest
newCustomerId
innerStopwatch
supportsIpv6OnIos
youTubeImporter
youtubeImporter
affine3D
but what about;
xmlHTTPRequest
where the capialized string features in the middle of the name?
Upvotes: 1
Views: 185
Reputation: 111
If i understood you correct you just have to add a + after [A-Z0-9] like this:
[a-z]+((\d)|([A-Z0-9]+[a-z0-9]+))*([A-Z])?
https://regex101.com/r/ONgcrA/1
Upvotes: 1
Reputation: 521794
I would use this version, which allows for multiple capital letters:
[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*
Here is a demo showing that the pattern is working for you new edge case.
Upvotes: 1