File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,13 @@ export const nothing: ParserWhichAlwaysSucceeds<undefined> = input =>
36
36
output : undefined ,
37
37
} )
38
38
39
- export const regularExpression =
40
- ( pattern : RegExp ) : Parser < string > =>
41
- input => {
42
- const match = pattern . exec ( input )
43
- return match === null || match . index !== 0
39
+ export const regularExpression = ( pattern : RegExp ) : Parser < string > => {
40
+ const patternAnchoredToStartOfString = pattern . source . startsWith ( '^' )
41
+ ? pattern
42
+ : new RegExp ( `^${ pattern . source } ` , pattern . flags )
43
+ return input => {
44
+ const match = patternAnchoredToStartOfString . exec ( input )
45
+ return match === null
44
46
? either . makeLeft ( {
45
47
input,
46
48
message : 'input did not match regular expression' ,
@@ -50,3 +52,4 @@ export const regularExpression =
50
52
output : match [ 0 ] ,
51
53
} )
52
54
}
55
+ }
You can’t perform that action at this time.
0 commit comments