Skip to content

Commit

Permalink
JavaScript: Improve Regexp pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Apr 13, 2018
1 parent 1bf73b0 commit 5b043cf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Expand Up @@ -8,7 +8,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\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
Expand Up @@ -731,7 +731,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\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
4 changes: 3 additions & 1 deletion tests/languages/javascript/regex_feature.test
Expand Up @@ -5,6 +5,7 @@
/foo\//
1 / 4 + "/, not a regex";
/ '1' '2' '3' '4' '5' /
[/foo/]

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

Expand All @@ -15,7 +16,8 @@
["regex", "/foo\"test\"bar/"], ["punctuation", ";"],
["regex", "/foo\\//"],
["number", "1"], ["operator", "/"], ["number", "4"], ["operator", "+"], ["string", "\"/, not a regex\""], ["punctuation", ";"],
["regex", "/ '1' '2' '3' '4' '5' /"]
["regex", "/ '1' '2' '3' '4' '5' /"],
["punctuation", "["], ["regex", "/foo/"], ["punctuation", "]"]
]

----------------------------------------------------
Expand Down

0 comments on commit 5b043cf

Please sign in to comment.