@@ -318,6 +318,16 @@ Methods to Search and Replace
318
318
// checks if the string contents are exactly the same as the given contents
319
319
u('foo')->equalsTo('foo'); // true
320
320
321
+ // checks if the string content match the given regular expression.
322
+ // You can pass flags for preg_match() as second argument. If PREG_PATTERN_ORDER
323
+ // or PREG_SET_ORDER are passed, preg_match_all() will be used.
324
+ u('avatar-73647.png')->match('/avatar-(\d+)\.png/');
325
+ // result = ['avatar-73647.png', '73647']
326
+ u('avatar-73647.png')->match('/avatar-(\d+)(-\d+)?\.png/', \PREG_UNMATCHED_AS_NULL);
327
+ // result = ['avatar-73647.png', '73647', null]
328
+ u('206-555-0100 and 800-555-1212')->match('/\d{3}-\d{3}-\d{4}/', \PREG_PATTERN_ORDER);
329
+ // result = [['206-555-0100', '800-555-1212']]
330
+
321
331
// checks if the string contains any of the other given strings
322
332
u('aeiou')->containsAny('a'); // true
323
333
u('aeiou')->containsAny(['ab', 'efg']); // false
@@ -354,22 +364,6 @@ Methods to Search and Replace
354
364
355
365
The ``containsAny() `` method was introduced in Symfony 5.1.
356
366
357
- ::
358
-
359
- You can use ``match() `` to search with a Regular Expression::
360
-
361
- u('avatar-73647.png')->match('/avatar-(\d+)\.png/');
362
- // result = ['avatar-73647.png', '73647']
363
-
364
- By default, PHP's ``preg_match() `` is used, and you can pass search flags as second argument::
365
-
366
- $string->match('/(a)(b)/', \PREG_UNMATCHED_AS_NULL);
367
-
368
- When passing ``\PREG_PATTERN_ORDER `` or ``\PREG_SET_ORDER ``, PHP's ``preg_match_all() `` is used.
369
- Multiple flags can be set with the `| ` operator::
370
-
371
- $string->match('/(a)(b)/', \PREG_PATTERN_ORDER|\PREG_UNMATCHED_AS_NULL);
372
-
373
367
Methods to Join, Split, Truncate and Reverse
374
368
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
375
369
0 commit comments