Skip to content

Commit

Permalink
JavaScript: Improve Regex matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 26, 2018
1 parent 9084481 commit 172d351
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
lookbehind: true,
greedy: true
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
lookbehind: true,
greedy: true
},
Expand Down
8 changes: 4 additions & 4 deletions tests/languages/javascript/regex_feature.test
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/foo bar/
/foo bar/;
/foo/gimyu,
/[\[\]]{2,4}(?:foo)*/;
/foo"test"bar/
/foo"test"bar/;
/foo\//
1 / 4 + "/, not a regex";
/ '1' '2' '3' '4' '5' /

----------------------------------------------------

[
["regex", "/foo bar/"],
["regex", "/foo bar/"], ["punctuation", ";"],
["regex", "/foo/gimyu"], ["punctuation", ","],
["regex", "/[\\[\\]]{2,4}(?:foo)*/"], ["punctuation", ";"],
["regex", "/foo\"test\"bar/"],
["regex", "/foo\"test\"bar/"], ["punctuation", ";"],
["regex", "/foo\\//"],
["number", "1"], ["operator", "/"], ["number", "4"], ["operator", "+"], ["string", "\"/, not a regex\""], ["punctuation", ";"],
["regex", "/ '1' '2' '3' '4' '5' /"]
Expand Down

0 comments on commit 172d351

Please sign in to comment.