From 683a6712aa8b3134a5ed035fa7015bd2ee0f0e39 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 20 Jan 2022 20:29:27 +0100 Subject: [PATCH 1/2] 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. --- components/string.rst | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/components/string.rst b/components/string.rst index f754bfdb7ea..3fc50077094 100644 --- a/components/string.rst +++ b/components/string.rst @@ -318,10 +318,6 @@ Methods to Search and Replace // checks if the string contents are exactly the same as the given contents u('foo')->equalsTo('foo'); // true - // checks if the string content match the given regular expression - u('avatar-73647.png')->match('/avatar-(\d+)\.png/'); - // result = ['avatar-73647.png', '73647'] - // checks if the string contains any of the other given strings u('aeiou')->containsAny('a'); // true u('aeiou')->containsAny(['ab', 'efg']); // false @@ -358,6 +354,22 @@ Methods to Search and Replace The ``containsAny()`` method was introduced in Symfony 5.1. +:: + +You can use ``match()`` to search with a Regular Expression:: + + u('avatar-73647.png')->match('/avatar-(\d+)\.png/'); + // result = ['avatar-73647.png', '73647'] + +By default, PHP's ``preg_match()`` is used, and you can pass search flags as second argument:: + + $string->match('/(a)(b)/', \PREG_UNMATCHED_AS_NULL); + +When passing ``\PREG_PATTERN_ORDER`` or ``\PREG_SET_ORDER``, PHP's ``preg_match_all()`` is used. +Multiple flags can be set with the `|` operator:: + + $string->match('/(a)(b)/', \PREG_PATTERN_ORDER|\PREG_UNMATCHED_AS_NULL); + Methods to Join, Split, Truncate and Reverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 4efdd760db1be434254e10bb114456272c9f67df Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Tue, 25 Jan 2022 14:54:34 +0100 Subject: [PATCH 2/2] Include match examples in the code block --- components/string.rst | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/components/string.rst b/components/string.rst index 3fc50077094..d5110cac96f 100644 --- a/components/string.rst +++ b/components/string.rst @@ -318,6 +318,16 @@ Methods to Search and Replace // checks if the string contents are exactly the same as the given contents u('foo')->equalsTo('foo'); // true + // checks if the string content match the given regular expression. + // You can pass flags for preg_match() as second argument. If PREG_PATTERN_ORDER + // or PREG_SET_ORDER are passed, preg_match_all() will be used. + u('avatar-73647.png')->match('/avatar-(\d+)\.png/'); + // result = ['avatar-73647.png', '73647'] + u('avatar-73647.png')->match('/avatar-(\d+)(-\d+)?\.png/', \PREG_UNMATCHED_AS_NULL); + // result = ['avatar-73647.png', '73647', null] + u('206-555-0100 and 800-555-1212')->match('/\d{3}-\d{3}-\d{4}/', \PREG_PATTERN_ORDER); + // result = [['206-555-0100', '800-555-1212']] + // checks if the string contains any of the other given strings u('aeiou')->containsAny('a'); // true u('aeiou')->containsAny(['ab', 'efg']); // false @@ -354,22 +364,6 @@ Methods to Search and Replace The ``containsAny()`` method was introduced in Symfony 5.1. -:: - -You can use ``match()`` to search with a Regular Expression:: - - u('avatar-73647.png')->match('/avatar-(\d+)\.png/'); - // result = ['avatar-73647.png', '73647'] - -By default, PHP's ``preg_match()`` is used, and you can pass search flags as second argument:: - - $string->match('/(a)(b)/', \PREG_UNMATCHED_AS_NULL); - -When passing ``\PREG_PATTERN_ORDER`` or ``\PREG_SET_ORDER``, PHP's ``preg_match_all()`` is used. -Multiple flags can be set with the `|` operator:: - - $string->match('/(a)(b)/', \PREG_PATTERN_ORDER|\PREG_UNMATCHED_AS_NULL); - Methods to Join, Split, Truncate and Reverse ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~