Javascript Regex for colon?

javascript, regex

Solution

Name starts with a capital letter. The regex should also match name starting with a capital N.

- If you want the entire regex to be case insensitive, add the `i` flag at the end.

- If you only want name to start with a lower or upper case N, then use a set

The `*` means 0 or more. The `?` is not needed anymore.

Something like this should work

/Name\s*:\s*\w*/g    //matches "Name"

/[Nn]ame\s*:\s*\w*/g //matches "Name" or "name"

/name\s*:\s*\w*/gi   //the entire regex is case insensitive

Problem

I'm wondering how I can use javascript regex to match a word like: `Name:` with all variations of spaces ? This is where I'm getting stuck. i.e. - `Name<space>: Fred` - `Name:<space>Fred` or `Name<space>:<space>Fred` Note the positioning of the spaces after the name, after the colon etc ? I was hoping something like `/(name(\s*:\s*)?)\w/g` would work but it doesn't :(

Original source