- Notifications
You must be signed in to change notification settings - Fork 5
Closed
Description
Describe the bug
Due to the missing constructor (issue #74) I tried to use anyOf('.') in the following:
const period = anyOf('.') const hostname = [host, optional(repeat([period, host], { min: 1, max: 255 }))];
The result was an unescaped period ('.') (match any character) in the regex. This caused a number of weird issues
which kept me company all weekend.
I then tried an escaped period in the anyOf:
const period = anyOf('\.') const hostname = [host, optional(repeat([period, host], { min: 1, max: 255 }))];
There was no change, the result was an unescaped period.
To Reproduce
import { buildRegExp, anyOf } from '..'; const period = anyOf('.'); const regex = buildRegExp(period); console.log(regex.source); console.log(regex); const escapedPeriod = anyOf('\.'); const escapedRegex = buildRegExp(escapedPeriod); console.log(escapedRegex.source); console.log(escapedRegex); test('`plain period`', () => { expect(regex.source).toBe('.'); expect(regex).toEqualRegex(RegExp(/./)); expect(regex).toMatchString('.'); expect(regex).not.toMatchString('a'); }); test('`escapedRegex`', () => { expect(escapedRegex.source).toBe('.'); expect(escapedRegex).toEqualRegex(RegExp(/\./)); expect(escapedRegex).toMatchString('.'); expect(escapedRegex).toMatchString('a'); });
Expected behavior
I expected to match the period in hostnames (i.e. www.google.com).
Screenshots
If applicable, add screenshots to help explain your problem.
Package version
ts-regex-builder: ???
Metadata
Metadata
Assignees
Labels
No labels