re2 2.24.0-aarch64-linux-gnu → 2.25.0-aarch64-linux-gnu
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.
- checksums.yaml +4 -4
- data/README.md +107 -4
- data/ext/re2/re2.cc +399 -31
- data/lib/3.1/re2.so +0 -0
- data/lib/3.2/re2.so +0 -0
- data/lib/3.3/re2.so +0 -0
- data/lib/3.4/re2.so +0 -0
- data/lib/4.0/re2.so +0 -0
- data/lib/re2/string.rb +6 -6
- data/lib/re2/version.rb +1 -1
- data/spec/re2/match_data_spec.rb +312 -0
- data/spec/re2/regexp_spec.rb +58 -1
- data/spec/re2_spec.rb +145 -43
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 992dc0b6a56f177c1e6a6421737779cd45981071f3afe62a788930c6e1c3a390
|
|
4
|
+
data.tar.gz: 1bb490277db9d2801c246b599303f39ad475fc56be4bf2abf2c11c860e6db277
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 856d8832fe492ecc9a140fc2ba4c81725b3827e21c58145e896c360c7679f7e293d4fe03427ff2f54066667632dea1d93314c655e8460999b12622567109fda9
|
|
7
|
+
data.tar.gz: d3ee08fd8464252e5f674fa59c8d3d9da2fc0b093db659ec108f99a6392c70b6a020af2cb2f7abbaa7622a5d77a3f8102a52ed1ccd886690ff3a55cdfa39d11d
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Python".
|
|
|
6
6
|
|
|
7
7
|
[](https://github.com/mudge/re2/actions)
|
|
8
8
|
|
|
9
|
-
**Current version:** 2.
|
|
9
|
+
**Current version:** 2.25.0
|
|
10
10
|
**Bundled RE2 version:** libre2.11 (2025-11-05)
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
@@ -27,6 +27,8 @@ RE2('(\w+):(\d+)').full_match("ruby:1234")
|
|
|
27
27
|
* [Submatch extraction](#submatch-extraction)
|
|
28
28
|
* [Scanning text incrementally](#scanning-text-incrementally)
|
|
29
29
|
* [Searching simultaneously](#searching-simultaneously)
|
|
30
|
+
* [Replacing and extracting](#replacing-and-extracting)
|
|
31
|
+
* [Escaping](#escaping)
|
|
30
32
|
* [Encoding](#encoding)
|
|
31
33
|
* [Requirements](#requirements)
|
|
32
34
|
* [Native gems](#native-gems)
|
|
@@ -165,7 +167,72 @@ m["word"] #=> "ruby"
|
|
|
165
167
|
m["number"] #=> "1234"
|
|
166
168
|
```
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
Multiple submatches can be retrieved at the same time by numeric index or name with [`values_at`](https://mudge.name/re2/RE2/MatchData.html#values_at-instance_method):
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
m = RE2('(?P<word>\w+):(?P<number>\d+):(\d+)').full_match("ruby:1234:5678")
|
|
174
|
+
#=> #<RE2::MatchData "ruby:1234:5678" 1:"ruby" 2:"1234" 3:"5678">
|
|
175
|
+
|
|
176
|
+
m.values_at("word", :number, 3)
|
|
177
|
+
#=> ["ruby", "1234", "5678"]
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
All captures can be returned as an array with [`captures`](https://mudge.name/re2/RE2/MatchData.html#captures-instance_method):
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
m = RE2('(?P<word>\w+):(?P<number>\d+):(\d+)').full_match("ruby:1234:5678")
|
|
184
|
+
#=> #<RE2::MatchData "ruby:1234:5678" 1:"ruby" 2:"1234" 3:"5678">
|
|
185
|
+
|
|
186
|
+
m.captures #=> ["ruby", "1234", "5678"]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Capturing group names are available on both `RE2::Regexp` and `RE2::MatchData`:
|
|
190
|
+
|
|
191
|
+
```ruby
|
|
192
|
+
re = RE2('(?P<word>\w+):(?P<number>\d+):(\d+)')
|
|
193
|
+
re.names #=> ["number", "word"]
|
|
194
|
+
|
|
195
|
+
m = re.full_match("ruby:1234:5678")
|
|
196
|
+
m.names #=> ["number", "word"]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Named captures can be returned as a hash with [`named_captures`](https://mudge.name/re2/RE2/MatchData.html#named_captures-instance_method):
|
|
200
|
+
|
|
201
|
+
```ruby
|
|
202
|
+
m = RE2('(?P<word>\w+):(?P<number>\d+):(\d+)').full_match("ruby:1234:5678")
|
|
203
|
+
#=> #<RE2::MatchData "ruby:1234:5678" 1:"ruby" 2:"1234" 3:"5678">
|
|
204
|
+
|
|
205
|
+
m.named_captures
|
|
206
|
+
#=> {"number" => "1234", "word" => "ruby"}
|
|
207
|
+
m.named_captures(symbolize_names: true)
|
|
208
|
+
#=> {number: "1234", word: "ruby"}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
This is [also available](https://mudge.name/re2/RE2/Regexp.html#named_captures-instance_method) on the original `RE2::Regexp` but will return the corresponding numerical index for each group:
|
|
212
|
+
|
|
213
|
+
```ruby
|
|
214
|
+
re = RE2('(?P<word>\w+):(?P<number>\d+):(\d+)')
|
|
215
|
+
re.named_captures
|
|
216
|
+
#=> {"number" => 2, "word" => 1}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The strings before and after a match can be returned with [`pre_match`](https://mudge.name/re2/RE2/MatchData.html#pre_match-instance_method) and [`post_match`](https://mudge.name/re2/RE2/MatchData.html#post_match-instance_method):
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
m = RE2::Regexp.new('(\d+)').partial_match("bob 123 456")
|
|
223
|
+
m.pre_match #=> "bob "
|
|
224
|
+
m.post_match #=> " 456"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The [`offset`](https://mudge.name/re2/RE2/MatchData.html#offset-instance_method) and [`match_length`](https://mudge.name/re2/RE2/MatchData.html#match_length-instance_method) of a match can be retrieved by index or name:
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
m = RE2::Regexp.new('(\d+)').partial_match("bob 123 456")
|
|
231
|
+
m.offset(1) #=> [4, 7]
|
|
232
|
+
m.match_length(1) #=> 3
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`RE2::MatchData` objects can also be used with Ruby's [pattern matching](https://docs.ruby-lang.org/en/3.2/syntax/pattern_matching_rdoc.html):
|
|
169
236
|
|
|
170
237
|
```ruby
|
|
171
238
|
case RE2('(\w+):(\d+)').full_match("ruby:1234")
|
|
@@ -238,6 +305,42 @@ set.match("abcdefghi") #=> [0, 1, 2]
|
|
|
238
305
|
set.match("ghidefabc") #=> [2, 1, 0]
|
|
239
306
|
```
|
|
240
307
|
|
|
308
|
+
### Replacing and extracting
|
|
309
|
+
|
|
310
|
+
[`RE2.replace`](https://mudge.name/re2/RE2.html#replace-class_method) returns a copy of a given string with the first occurrence of a pattern replaced with a given rewrite string:
|
|
311
|
+
|
|
312
|
+
```ruby
|
|
313
|
+
RE2.replace("hello there", "hello", "howdy") #=> "howdy there"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The pattern can be given as either a string or an `RE2::Regexp`:
|
|
317
|
+
|
|
318
|
+
```ruby
|
|
319
|
+
re = RE2('hel+o')
|
|
320
|
+
RE2.replace("hello there", re, "yo") #=> "yo there"
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
To replace _all_ matches and not just the first, use [`RE2.global_replace`](https://mudge.name/re2/RE2.html#global_replace-class_method):
|
|
324
|
+
|
|
325
|
+
```ruby
|
|
326
|
+
RE2.global_replace("hallo thare", "a", "e") #=> "hello there"
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
To extract matches with a given rewrite string including substitutions, use [`RE2.extract`](https://mudge.name/re2/RE2.html#extract-class_method):
|
|
330
|
+
|
|
331
|
+
```ruby
|
|
332
|
+
RE2.extract("alice@example.com", '(\w+)@(\w+)', '\2-\1')
|
|
333
|
+
#=> "example-alice"
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Escaping
|
|
337
|
+
|
|
338
|
+
To escape all potentially meaningful regexp characters in a string, use [`RE2.escape`](https://mudge.name/re2/RE2.html#escape-class_method):
|
|
339
|
+
|
|
340
|
+
```ruby
|
|
341
|
+
RE2.escape("1.5-2.0?") #=> "1\\.5\\-2\\.0\\?"
|
|
342
|
+
```
|
|
343
|
+
|
|
241
344
|
### Encoding
|
|
242
345
|
|
|
243
346
|
> [!WARNING]
|
|
@@ -250,10 +353,10 @@ the right encoding so this is the responsibility of the caller, e.g.
|
|
|
250
353
|
|
|
251
354
|
```ruby
|
|
252
355
|
# By default, RE2 will process patterns and text as UTF-8
|
|
253
|
-
RE2(non_utf8_pattern.encode("UTF-8")).
|
|
356
|
+
RE2(non_utf8_pattern.encode("UTF-8")).partial_match(non_utf8_text.encode("UTF-8"))
|
|
254
357
|
|
|
255
358
|
# If the :utf8 option is false, RE2 will process patterns and text as ISO-8859-1
|
|
256
|
-
RE2(non_latin1_pattern.encode("ISO-8859-1"), utf8: false).
|
|
359
|
+
RE2(non_latin1_pattern.encode("ISO-8859-1"), utf8: false).partial_match(non_latin1_text.encode("ISO-8859-1"))
|
|
257
360
|
```
|
|
258
361
|
|
|
259
362
|
## Requirements
|