Hi, I'm fairly new to Regex. Hoping someone would help me find a regular expression for finding occurrences of uppercase followed by lowercase. For example:
ABcDe
Here I would be hoping to find the 'B' and the 'D'
Thanks!
Hi, I'm fairly new to Regex. Hoping someone would help me find a regular expression for finding occurrences of uppercase followed by lowercase. For example:
ABcDe
Here I would be hoping to find the 'B' and the 'D'
Thanks!
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})");
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) ]