re2js 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -54
- package/build/index.cjs.cjs +425 -156
- package/build/index.cjs.cjs.map +1 -1
- package/build/index.esm.d.ts +3 -1
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +425 -156
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +425 -156
- package/build/index.umd.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -118,49 +118,6 @@ RE2JS.compile(
|
|
|
118
118
|
).matches('AB\nc') // true
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
### Finding Matches
|
|
122
|
-
|
|
123
|
-
To find a match for a given regex pattern in a string, you can use the `find()` function
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
import { RE2JS } from 're2js'
|
|
127
|
-
|
|
128
|
-
RE2JS.compile('ab+c').matcher('xxabbbc').find() // true
|
|
129
|
-
RE2JS.compile('ab+c').matcher('cbbba').find() // false
|
|
130
|
-
// with flags
|
|
131
|
-
RE2JS.compile('ab+c', RE2JS.CASE_INSENSITIVE).matcher('abBBc').find() // true
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Example to collect all matches in string
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
import { RE2JS } from 're2js'
|
|
138
|
-
|
|
139
|
-
const p = RE2JS.compile('abc+')
|
|
140
|
-
const matchString = p.matcher('abc abcccc abcc')
|
|
141
|
-
const results = []
|
|
142
|
-
while (matchString.find()) {
|
|
143
|
-
results.push(matchString.group())
|
|
144
|
-
}
|
|
145
|
-
results // ['abc', 'abcccc', 'abcc']
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
The `find()` method searches for a pattern match in a string starting from a specific index
|
|
149
|
-
|
|
150
|
-
```js
|
|
151
|
-
import { RE2JS } from 're2js'
|
|
152
|
-
|
|
153
|
-
const p = RE2JS.compile('.*[aeiou]')
|
|
154
|
-
const matchString = p.matcher('abcdefgh')
|
|
155
|
-
matchString.find(0) // true
|
|
156
|
-
matchString.group() // 'abcde'
|
|
157
|
-
matchString.find(1) // true
|
|
158
|
-
matchString.group() // 'bcde'
|
|
159
|
-
matchString.find(4) // true
|
|
160
|
-
matchString.group() // 'e'
|
|
161
|
-
matchString.find(7) // false
|
|
162
|
-
```
|
|
163
|
-
|
|
164
121
|
### High-Performance Boolean Testing
|
|
165
122
|
|
|
166
123
|
If you only need to know **whether** a string matches a pattern (without extracting capture groups), you should use the `test()`, `testExact()`, or `matches()` methods. Unlike `.matcher()`, these methods do not instantiate stateful `Matcher` objects and request exactly `0` capture groups. This guarantees that execution is securely routed to the high-speed DFA (Deterministic Finite Automaton) engine whenever possible in linear `O(n)` time
|
|
@@ -210,28 +167,47 @@ RE2JS.compile('abc').matcher('ab').lookingAt() // false
|
|
|
210
167
|
|
|
211
168
|
Note that the `lookingAt` method only checks the start of the string. It does not search the entire string for a match
|
|
212
169
|
|
|
213
|
-
###
|
|
170
|
+
### Finding Matches
|
|
214
171
|
|
|
215
|
-
|
|
172
|
+
To find a match for a given regex pattern in a string, you can use the `find()` function
|
|
216
173
|
|
|
217
174
|
```js
|
|
218
175
|
import { RE2JS } from 're2js'
|
|
219
176
|
|
|
220
|
-
RE2JS.compile('
|
|
221
|
-
RE2JS.compile('
|
|
222
|
-
|
|
177
|
+
RE2JS.compile('ab+c').matcher('xxabbbc').find() // true
|
|
178
|
+
RE2JS.compile('ab+c').matcher('cbbba').find() // false
|
|
179
|
+
// with flags
|
|
180
|
+
RE2JS.compile('ab+c', RE2JS.CASE_INSENSITIVE).matcher('abBBc').find() // true
|
|
223
181
|
```
|
|
224
182
|
|
|
225
|
-
|
|
183
|
+
Example to collect all matches in string
|
|
226
184
|
|
|
227
185
|
```js
|
|
228
186
|
import { RE2JS } from 're2js'
|
|
229
187
|
|
|
230
|
-
RE2JS.compile('
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
188
|
+
const p = RE2JS.compile('abc+')
|
|
189
|
+
const matchString = p.matcher('abc abcccc abcc')
|
|
190
|
+
const results = []
|
|
191
|
+
while (matchString.find()) {
|
|
192
|
+
results.push(matchString.group())
|
|
193
|
+
}
|
|
194
|
+
results // ['abc', 'abcccc', 'abcc']
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The `find()` method searches for a pattern match in a string starting from a specific index
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
import { RE2JS } from 're2js'
|
|
201
|
+
|
|
202
|
+
const p = RE2JS.compile('.*[aeiou]')
|
|
203
|
+
const matchString = p.matcher('abcdefgh')
|
|
204
|
+
matchString.find(0) // true
|
|
205
|
+
matchString.group() // 'abcde'
|
|
206
|
+
matchString.find(1) // true
|
|
207
|
+
matchString.group() // 'bcde'
|
|
208
|
+
matchString.find(4) // true
|
|
209
|
+
matchString.group() // 'e'
|
|
210
|
+
matchString.find(7) // false
|
|
235
211
|
```
|
|
236
212
|
|
|
237
213
|
### Multi-Pattern Matching (RE2Set)
|
|
@@ -347,6 +323,30 @@ router.compile()
|
|
|
347
323
|
console.log(router.execute('/users/42')) // Outputs: "User ID: 42"
|
|
348
324
|
```
|
|
349
325
|
|
|
326
|
+
### Splitting Strings
|
|
327
|
+
|
|
328
|
+
You can split a string based on a regex pattern using the `split()` function
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
import { RE2JS } from 're2js'
|
|
332
|
+
|
|
333
|
+
RE2JS.compile('/').split('abcde') // ['abcde']
|
|
334
|
+
RE2JS.compile('/').split('a/b/cc//d/e//') // ['a', 'b', 'cc', '', 'd', 'e']
|
|
335
|
+
RE2JS.compile(':').split(':a::b') // ['', 'a', '', 'b']
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The `split()` function also supports a limit parameter
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
import { RE2JS } from 're2js'
|
|
342
|
+
|
|
343
|
+
RE2JS.compile('/').split('a/b/cc//d/e//', 3) // ['a', 'b', 'cc//d/e//']
|
|
344
|
+
RE2JS.compile('/').split('a/b/cc//d/e//', 4) // ['a', 'b', 'cc', '/d/e//']
|
|
345
|
+
RE2JS.compile('/').split('a/b/cc//d/e//', 9) // ['a', 'b', 'cc', '', 'd', 'e', '', '']
|
|
346
|
+
RE2JS.compile(':').split('boo:and:foo', 2) // ['boo', 'and:foo']
|
|
347
|
+
RE2JS.compile(':').split('boo:and:foo', 5) // ['boo', 'and', 'foo']
|
|
348
|
+
```
|
|
349
|
+
|
|
350
350
|
### Working with Groups
|
|
351
351
|
|
|
352
352
|
RE2JS supports capturing groups in regex patterns
|