philiprehberger-regex_lib 0.6.0 → 0.7.0
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/CHANGELOG.md +5 -0
- data/README.md +12 -0
- data/lib/philiprehberger/regex_lib/version.rb +1 -1
- data/lib/philiprehberger/regex_lib.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c679a94104bc2a1af5329e43737060db3a8a9dd9eb8a5672f30ad095d5b6aaf4
|
|
4
|
+
data.tar.gz: c82822e809f812e605d338a689ea344d7fd82abae6128824347a2271141acc39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2339d7485948605cb49e7e5a2a52800ea33724c2660b4ac4a9fa9664153bb27b03072c41ed68fdf0b07f6f26e2e2007058ee9a861bf1b3172cfd010726084c57
|
|
7
|
+
data.tar.gz: 9773d2ecd44db34f84a8ebe9d2e4b893c38191773ce7f0cfe604cad1048a122eb5ace7f26e099770bdcd9cc240f2d7cd7c6fa955c0ffcc4eb59a71435185c2bd
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-06-14
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `RegexLib.any_match?(pattern_name, *strings)` — true if any of the supplied strings matches the named pattern. Convenience wrapper for the common `any? { |s| match?(name, s) }` pattern in form-validation use cases.
|
|
14
|
+
|
|
10
15
|
## [0.6.0] - 2026-04-22
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-regex_lib)
|
|
5
5
|
[](https://github.com/philiprehberger/rb-regex-lib/commits/main)
|
|
6
6
|
|
|
7
|
+

|
|
8
|
+
|
|
7
9
|
Pre-built regex patterns for emails, URLs, IPs, dates, and more
|
|
8
10
|
|
|
9
11
|
## Requirements
|
|
@@ -195,11 +197,21 @@ Philiprehberger::RegexLib.scan(text).select { |r| [:ssn, :credit_card].include?(
|
|
|
195
197
|
| `CRON_EXPRESSION` | Cron expression (minute hour day month weekday) |
|
|
196
198
|
| `CIDR` | CIDR notation (IPv4/prefix length) |
|
|
197
199
|
|
|
200
|
+
### Any-of Matching
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
require "philiprehberger/regex_lib"
|
|
204
|
+
|
|
205
|
+
inputs = ['not-an-email', 'foo@bar.com', 'also-not']
|
|
206
|
+
Philiprehberger::RegexLib.any_match?(:email, *inputs) # => true
|
|
207
|
+
```
|
|
208
|
+
|
|
198
209
|
## API
|
|
199
210
|
|
|
200
211
|
| Method | Description |
|
|
201
212
|
|--------|-------------|
|
|
202
213
|
| `RegexLib.match?(pattern_name, string)` | Test string against a named pattern, returns `true`/`false` |
|
|
214
|
+
| `.any_match?(name, *strings)` | True if any of the strings matches the named pattern |
|
|
203
215
|
| `RegexLib.extract(pattern_name, string)` | Extract named captures as a `Hash`, full match as `String`, or `nil` |
|
|
204
216
|
| `RegexLib.extract_all(pattern_name, string)` | Find all matches in the string, returns `Array<String>` |
|
|
205
217
|
| `RegexLib.count(pattern_name, string)` | Count non-overlapping matches in the string, returns `Integer` |
|
|
@@ -35,6 +35,20 @@ module Philiprehberger
|
|
|
35
35
|
pattern.match?(string)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
# True when at least one of the given strings matches the named pattern.
|
|
39
|
+
#
|
|
40
|
+
# Equivalent to `strings.any? { |s| match?(pattern_name, s) }` but avoids
|
|
41
|
+
# the closure allocation on call sites that just need a yes/no answer.
|
|
42
|
+
#
|
|
43
|
+
# @param pattern_name [Symbol] the pattern name (e.g. :email, :url, :ipv4)
|
|
44
|
+
# @param strings [Array<String>] the strings to test
|
|
45
|
+
# @return [Boolean] true if any string matches the pattern
|
|
46
|
+
# @raise [Error] if the pattern name is not recognized
|
|
47
|
+
def self.any_match?(pattern_name, *strings)
|
|
48
|
+
pattern = resolve_pattern!(pattern_name)
|
|
49
|
+
strings.any? { |s| pattern.match?(s) }
|
|
50
|
+
end
|
|
51
|
+
|
|
38
52
|
# Extract named captures from a string using a named pattern.
|
|
39
53
|
#
|
|
40
54
|
# @param pattern_name [Symbol] the pattern name (e.g. :date_iso, :semantic_version)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-regex_lib
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A library of tested, documented regex patterns for common data formats.
|
|
14
14
|
Includes named captures, validation helpers, and extraction methods.
|