Skip to content

Commit 683a671

Browse files
Moving RexExp search to its own heading
I wanted to create a heading ("Search Using a Regular Expression") for this. Is `~~~~` the lowest level already? If yes, I'd suggest to drop the "Method Reference" heading, and promote all included "Methods to..." headings one level.
1 parent 514156d commit 683a671

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

components/string.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,6 @@ Methods to Search and Replace
318318
// checks if the string contents are exactly the same as the given contents
319319
u('foo')->equalsTo('foo'); // true
320320

321-
// checks if the string content match the given regular expression
322-
u('avatar-73647.png')->match('/avatar-(\d+)\.png/');
323-
// result = ['avatar-73647.png', '73647']
324-
325321
// checks if the string contains any of the other given strings
326322
u('aeiou')->containsAny('a'); // true
327323
u('aeiou')->containsAny(['ab', 'efg']); // false
@@ -358,6 +354,22 @@ Methods to Search and Replace
358354

359355
The ``containsAny()`` method was introduced in Symfony 5.1.
360356

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+
361373
Methods to Join, Split, Truncate and Reverse
362374
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363375

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy