diff --git a/src/helper.ts b/src/helper.ts index 64ad795..d5bbeee 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -133,7 +133,11 @@ export const hexNumber = /^[0-9a-fA-F]+$/; export const octalNumber = /^[0-7]+$/; -export const charLiteral = /^(?:\\u[0-9a-fA-F]{4}$|\\x[0-9a-fA-F]{2}|\\\d{1,3})/; // last option refers to octal character or capture group backreference +// octal escape sequences are not matched here because they should be wrapped in a character class +export const negatableCharLiteral = /^(?:\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2})$/; + +// last option refers to octal character or capture group backreference +export const charLiteral = /^(?:\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}|\\\d{1,3})$/; export const captureName = /^[a-zA-Z_][a-zA-Z0-9_]*$/; diff --git a/src/modifiers/NegationModifier.ts b/src/modifiers/NegationModifier.ts index 57727ea..8aacb83 100644 --- a/src/modifiers/NegationModifier.ts +++ b/src/modifiers/NegationModifier.ts @@ -1,5 +1,5 @@ import { RegExpModifier } from '../types'; -import { charLiteral, isBracketGroup, isCharacterClass, negatableTokens } from '../helper'; +import { isBracketGroup, isCharacterClass, negatableCharLiteral, negatableTokens } from '../helper'; export default class NegationModifier implements RegExpModifier { public modify(regExp: string): [string, string?] { @@ -15,7 +15,7 @@ export default class NegationModifier implements RegExpModifier { case '$': return [`(?!${regExp})`]; default: - if (charLiteral.test(regExp)) { + if (negatableCharLiteral.test(regExp)) { return [`[^${regExp}]`]; } else if (negatableTokens.test(regExp)) { return [regExp.toUpperCase()];