Regex Question (Regular Expressions: Reuse Patterns Using Capture Groups) BETA

Regex Question (Regular Expressions: Reuse Patterns Using Capture Groups) BETA
0

#21

I thought ^ was a negation operator. Why is $ put at the end?


#22

^ is only the negation operator when it is at the start of a capturing group, like this: [^abc]

Otherwise, ^ matches the start of a string.

$ matches the end of a string.

You bring up a good point – regular expression syntax can be quite unclear because each character’s meaning depends on it’s context.


#23

You’re missing the second \s and the \2 is not needed.

let reRegex = /^(\d+)\s\1\s\1$/;