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 @@ -59,19 +59,22 @@ With `.not()` (aka. regex complement) this is easy:
5959``` typescript
6060import { RB } from ' @gruhn/regex-utils'
6161
62- const commentStart = RB (' /*' )
63- const commentEnd = RB (' */' )
64- const commentInner = commentEnd .not ()
62+ const commentInner = RB (/ ^ . * $ / ) // any string
63+ .concat (' */' ) // followed by comment end marker
64+ .concat (/ ^ . * $ / ) // followed by any string
65+ .not () // negate whole pattern
6566
66- const commentRegex = commentStart .concat (commentInner ).concat (commentEnd )
67+ const commentRegex = RB (' /*' )
68+ .concat (commentInner )
69+ .concat (' */' )
6770```
6871
6972With ` .toRegExp() ` we can convert back to a native JavaScript regex:
7073``` typescript
7174commentRegex .toRegExp ()
7275```
7376```
74- /^(\/\*((\*{2}(\/?\*)*(\/ [^\*]|[^\*\/])|\*(\/.| [^\*\/])| [^\*])(\*(\/?\*)*(\/[^\*]|[^\*\/])|[^\*])*\*(\/?\*)*\/|\*(\*(\/?\*)*\/|\/)) )$/
77+ /^(\/\*[^\*]*\*( [^\*\/][^\*]*\*|\*)*\/ )$/
7578```
7679
7780### Password Regex using Intersections
You can’t perform that action at this time.
0 commit comments