From 7a3b65b9e063276bd705b39795b3bd0233a42a65 Mon Sep 17 00:00:00 2001 From: azu Date: Wed, 18 May 2022 08:24:56 +0900 Subject: [PATCH 1/2] feat: support `s` and `d` flag - `s` means dotAll - `d` flag is just ignored --- src/regexp-parse.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/regexp-parse.ts b/src/regexp-parse.ts index e78f11f..138fcc9 100644 --- a/src/regexp-parse.ts +++ b/src/regexp-parse.ts @@ -1,4 +1,5 @@ -const REGEXP_LITERAL_PATTERN = /^\/(.*)\/([guimy]*)$/; +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags +const REGEXP_LITERAL_PATTERN = /^\/(.*)\/([guimysd]*)$/; export const parseRegExpString = (str: string): { source: string; flagString: string } | null => { const result = str.match(REGEXP_LITERAL_PATTERN); if (!result) { From 004d0a0e08279e5cd902768e683109633e89aab6 Mon Sep 17 00:00:00 2001 From: azu Date: Wed, 18 May 2022 08:25:55 +0900 Subject: [PATCH 2/2] test: add test for dotAll --- test/snapshots/dotAll-regexp/input-patterns.json | 3 +++ test/snapshots/dotAll-regexp/input.txt | 3 +++ test/snapshots/dotAll-regexp/output-for-human.md | 16 ++++++++++++++++ .../dotAll-regexp/output-for-machine.json | 8 ++++++++ 4 files changed, 30 insertions(+) create mode 100644 test/snapshots/dotAll-regexp/input-patterns.json create mode 100644 test/snapshots/dotAll-regexp/input.txt create mode 100644 test/snapshots/dotAll-regexp/output-for-human.md create mode 100644 test/snapshots/dotAll-regexp/output-for-machine.json diff --git a/test/snapshots/dotAll-regexp/input-patterns.json b/test/snapshots/dotAll-regexp/input-patterns.json new file mode 100644 index 0000000..7d70cea --- /dev/null +++ b/test/snapshots/dotAll-regexp/input-patterns.json @@ -0,0 +1,3 @@ +[ + "/.+/s" +] diff --git a/test/snapshots/dotAll-regexp/input.txt b/test/snapshots/dotAll-regexp/input.txt new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/test/snapshots/dotAll-regexp/input.txt @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/test/snapshots/dotAll-regexp/output-for-human.md b/test/snapshots/dotAll-regexp/output-for-human.md new file mode 100644 index 0000000..b5c60b0 --- /dev/null +++ b/test/snapshots/dotAll-regexp/output-for-human.md @@ -0,0 +1,16 @@ + +- match text: **1 +2 +3 +** +- captures: **[]** +- startIndex: **0** +- endIndex: **6** + +``` +**1 +2 +3 +** +``` + diff --git a/test/snapshots/dotAll-regexp/output-for-machine.json b/test/snapshots/dotAll-regexp/output-for-machine.json new file mode 100644 index 0000000..687a430 --- /dev/null +++ b/test/snapshots/dotAll-regexp/output-for-machine.json @@ -0,0 +1,8 @@ +[ + { + "match": "1\n2\n3\n", + "captures": [], + "startIndex": 0, + "endIndex": 6 + } +] \ No newline at end of file