You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_Note: You can use `EloquentRegex::builder()->pattern()` if you need just build a regex without source string_
211
+
210
212
Custom pattern builder supports a wide range of character classes and all special chars. Also, `literal` or `exact` method could be used to match exact string you need, or `char` method could be used to match exact character. The full list of pattern builder methods is comming soon. Before that, you can check this files out:
Quantifiers in regular expressions are symbols or sets of symbols that specify how many instances of a character, group, or character class must be present in the input for a match to be found. EloquentRegex enhances the way quantifiers are used, making it simpler and more intuitive to define the frequency of pattern occurrences.
222
+
223
+
### Optional Elements
224
+
225
+
To make an element optional, use '?'. This matches zero or one occurrence of the preceding element.
226
+
227
+
```php
228
+
// Matches a string that may or may not contain a dash
// Result would be true in both cases of $yourString: "123456" & "123-456"
231
+
```
232
+
233
+
### Specifying a Range
234
+
235
+
For specifying a range of occurrences, use a string with two numbers separated by a comma '2,5'. This matches the preceding element at least and at most the specified times.
// Result would be true in cases $yourString: "1235__158", but "1235___158" and "1235_158" will be false
271
+
272
+
```
273
+
274
+
### Custom Character Sets and groups
275
+
276
+
You can apply quantifiers to custom character sets and groups as second argument after the callback, matching a specific number of occurrences.
277
+
278
+
```php
279
+
// Matches strings with exactly 3 periods or colons
280
+
$regex = EloquentRegex::builder()->start()
281
+
->charSet(function ($pattern) {
282
+
$pattern->period()->colon();
283
+
}, '3')->toRegex();
284
+
// Result: ([\.\:]){3}
285
+
```
286
+
287
+
### Quantifier values
288
+
289
+
In [Special characters](https://github.com/MaestroError/eloquent-regex/blob/documentation-and-examples/src/Traits/BuilderPatternTraits/SpecificCharsTrait.php)
have different approach, lets take `digits` as example:
305
+
306
+
```php
307
+
// By defualt it is set as One or More
308
+
EloquentRegex::start($yourString)->digits();
309
+
310
+
// You can completly remove quantifier by passing 0 as first argument
311
+
EloquentRegex::start($yourString)->digits(0);
312
+
313
+
// You can specify exact amount of digit by passing int
314
+
EloquentRegex::start($yourString)->digits(5);
315
+
316
+
// You can specify range of digits by adding "Range" to the method
317
+
EloquentRegex::start($yourString)->digitsRange(1, 5); // Matches from 1 to 5 digits
318
+
```
226
319
227
320
##### To Do
228
321
229
-
- Add needed options for new patterns:
322
+
- Add options for new patterns:
230
323
- usernameLength: Set minimum and maximum length for the username part of the email.
231
324
- dateFormat, timeFormat: Specify the format of date and time (e.g., MM-DD-YYYY, HH:MM).
232
325
- Consider to register Patterns like options using key (name) => value (class) pairs (check performance) ✔️ (_No significant change before 50+ patterns_)
233
326
234
-
- Extend BuilderPattern, try to add methods:
235
-
236
-
- group(callable $callback): Creates a grouped subpattern.✔️
237
-
- nonCapturingGroup(callable $callback): Creates a non-capturing group.✔️
238
-
- orPattern(): Alternation, allowing for multiple possibilities.✔️
0 commit comments