Reputation: 1314
I want to split up a camelCase string with spaces.
"ClassicalMusicArtist" -> "Classical Music Artist"
I should be able to do this by replacing "/([a-z](?=[A-Z]))/g"
with "$1 "
(regex101).
But my regex is not getting any matches:
val regex = "/([a-z](?=[A-Z]))/g".r
val s = "ClassicalMusicArtist"
regex.replaceAllIn(s, "$1 ") // -> Returns "ClassicalMusicArtist"
regex.findFirstIn(s) // -> Returns None
What am I doing wrong? I used the regex in another language with success and can't figure out why I am not getting any matches.
Upvotes: 0
Views: 142
Reputation: 1314
Ok I figured it out.
In scala the regex has to be val regex = "([a-z](?=[A-Z]))".r
without the leading /
and the modifier.
Upvotes: 1