Reputation: 483
What regular expression can I use for finding occurrences of uppercase followed by lowercase?
For example:
ABcDe
Here I would be hoping to find the 'B' and the 'D'
Upvotes: 1
Views: 7773
Reputation: 1108
In Python:
import re
regex = re.compile("(?:([A-Z])[a-z])")
strdata = 'ABcDefGHIjk'
print [m.group(1) for m in regex.findinter(strdata) if m.group(1) ]
Upvotes: 0
Reputation: 65
In Javascript, you can do this:
let test_string = "This$IsTheTestForTest_purpose";
test_string.replace(/[\W_]|([a-z])(?=[A-Z])/g, "$1 ")
// console.log(test_string)
// This Is The Test For Test purpose
Upvotes: 0
Reputation: 72658
You can use forward lookaheads. You haven't said which "flavour" of regex you're using, so here's a C# example:
var regex = new Regex(@"[A-Z](?=[a-z])");
string str = "ABcDef";
regex.Replace(str, "?");
Console.WriteLine(str); // outputs "A?c?ef"
Additionally, for international characters, you can use Unicode character classes:
var regex = new Regex(@"\p{Lu}(?=\p{Ll})");
Upvotes: 9