Craig Harley Craig Harley - 6 months ago 66
Javascript Question

regex to match only one capital letter

I'm trying to match characters but I need to only match single capital letters.
For example:

'Hello World' - 2 matches
'Hello WOrld' - 1 match
'HEllo WOrld' - 0 matches

So far I have
but I think I've misinterpreted what a negative lookahead is.



I managed to fix this by using Edge.js to call a c# function from Node, this allowed me to get around the restrictions with Javascript regex.

The final code ended up looking like this:

const getPerson = edge.func(function () {/*
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;

 public class RegexReplacer {
    public string PutSpacesBeforeCaps (string input) {
        Regex regex = new Regex(@"((?<![0-9])(?<![A-Z])[A-Z](?![A-Z])(?![0-9]))");
        return regex.Replace(input, " $1");

 public class Startup {
    public async Task<object> Invoke(dynamic input) {
        RegexReplacer replacer = new RegexReplacer();
        return replacer.PutSpacesBeforeCaps(input.ToString());