Skip to content

Commit ef1675a

Browse files
committed
docs: fix error in comment example
1 parent 770782c commit ef1675a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ With `.not()` (aka. regex complement) this is easy:
5959
```typescript
6060
import { 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

6972
With `.toRegExp()` we can convert back to a native JavaScript regex:
7073
```typescript
7174
commentRegex.toRegExp()
7275
```
7376
```
74-
/^(\/\*((\*{2}(\/?\*)*(\/[^\*]|[^\*\/])|\*(\/.|[^\*\/])|[^\*])(\*(\/?\*)*(\/[^\*]|[^\*\/])|[^\*])*\*(\/?\*)*\/|\*(\*(\/?\*)*\/|\/)))$/
77+
/^(\/\*[^\*]*\*([^\*\/][^\*]*\*|\*)*\/)$/
7578
```
7679

7780
### Password Regex using Intersections

0 commit comments

Comments
 (0)