125-Regular-Expressions https://regex101.com/

001- serach PHP in string
Found.

002 - Case Incensitive
Found.

003 - match multiple word in string ,return an array
Array
(
    [0] => Array
        (
            [0] => PHP
            [1] => php
        )

)

004 - Multiple word search in Array
Array
(
    [0] => Array
        (
            [0] => PHP
            [1] => web
            [2] => php
            [3] => web
            [4] => web
        )

)

004-a - if need to print Only For One Value form array
PHP
web
005 - many single characters search in one go
Array
(
    [0] => Array
        (
            [0] => t
            [1] => w
            [2] => t
            [3] => w
            [4] => o
            [5] => o
            [6] => w
        )

)

006 - Search Even Numbers
Array
(
    [0] => 522
)

007 - Character Set, search multiple value in string without using pipe sign
Array
(
    [0] => Array
        (
            [0] => w
        )

)

008 - search all except the input chracter by user, like = not search = ^wot
Array
(
    [0] => Array
        (
            [0] => P
            [1] => H
            [2] => P
            [3] =>  
            [4] => i
            [5] => s
            [6] =>  
            [7] => h
            [8] => e
            [9] =>  
            [10] => e
            [11] => b
            [12] =>  
            [13] => s
            [14] => c
            [15] => r
            [16] => i
            [17] => p
            [18] => i
            [19] => n
            [20] => g
            [21] =>  
            [22] => l
            [23] => a
            [24] => n
            [25] => g
            [26] => u
            [27] => a
            [28] => g
            [29] => e
            [30] =>  
            [31] => f
            [32] =>  
            [33] => 5
            [34] => 2
            [35] => 2
            [36] =>  
            [37] => c
            [38] => h
            [39] => i
            [40] => c
            [41] => e
            [42] => .
            [43] =>  
            [44] => 8
            [45] => 2
            [46] => 5
        )

)

009 - Range, like = search all characters from a to c
Array
(
    [0] => Array
        (
            [0] => b
            [1] => c
            [2] => a
            [3] => a
            [4] => c
            [5] => c
        )

)

010 - Range upper and lower search without using italic character = i
Array
(
    [0] => Array
        (
            [0] => H
            [1] => i
            [2] => h
            [3] => e
            [4] => e
            [5] => b
            [6] => c
            [7] => i
            [8] => i
            [9] => g
            [10] => a
            [11] => g
            [12] => a
            [13] => g
            [14] => e
            [15] => f
            [16] => c
            [17] => h
            [18] => i
            [19] => c
            [20] => e
        )

)

011 - search number and charcter without using pipe sign in one go
Array
(
    [0] => Array
        (
            [0] => b
            [1] => c
            [2] => a
            [3] => a
            [4] => 5
            [5] => 2
            [6] => 2
            [7] => c
            [8] => c
            [9] => 8
            [10] => 2
            [11] => 5
        )

)

012 - search same character name with end defferent , like = search file2 in string (file1 file2 file3)
Array
(
    [0] => Array
        (
            [0] => file1
            [1] => file2
            [2] => file3
        )

)

013 - search end different with range
Array
(
    [0] => Array
        (
            [0] => file1
            [1] => file2
            [2] => file3
            [3] => file5
            [4] => file6
        )

)

014 - search above with numbers
Array
(
    [0] => Array
        (
            [0] => 2015
            [1] => 2016
            [2] => 2017
            [3] => 2018
        )

)

015 - search word whihc start , end and in middle must have user defined characters
Array
(
    [0] => Array
        (
            [0] => web
        )

)

017 - above code with range fucntion in middle
Array
(
    [0] => Array
        (
            [0] => web
        )

)

018 - above code with characters
Array
(
    [0] => Array
        (
            [0] => bat
            [1] => cat
        )

)

019 - Meta characters, select all chracter excepts . and -
Array
(
    [0] => Array
        (
            [0] => P
            [1] => H
            [2] => P
            [3] => i
            [4] => s
            [5] => t
            [6] => h
            [7] => e
            [8] => w
            [9] => e
            [10] => b
            [11] => s
            [12] => c
            [13] => r
            [14] => i
            [15] => p
            [16] => t
            [17] => i
            [18] => n
            [19] => g
            [20] => l
            [21] => a
            [22] => n
            [23] => g
            [24] => u
            [25] => a
            [26] => g
            [27] => e
            [28] => o
            [29] => f
            [30] => 5
            [31] => 2
            [32] => 2
            [33] => c
            [34] => h
            [35] => o
            [36] => i
            [37] => c
            [38] => e
            [39] => 8
            [40] => 2
            [41] => 5
        )

)

020 - Capital W - all spaces and other sign, leave the numbers and characters
Array
(
    [0] => Array
        (
            [0] =>  
            [1] =>  
            [2] =>  
            [3] =>  
            [4] =>  
            [5] =>  
            [6] =>  
            [7] =>  
            [8] => .
            [9] =>  
        )

)

021 - Matches any digit from 0 to 9
Array
(
    [0] => Array
        (
            [0] => 5
            [1] => 2
            [2] => 2
            [3] => 8
            [4] => 2
            [5] => 5
        )

)

022 - Capital D -- return all char, sign except numbers
Array
(
    [0] => Array
        (
            [0] => P
            [1] => H
            [2] => P
            [3] =>  
            [4] => i
            [5] => s
            [6] =>  
            [7] => t
            [8] => h
            [9] => e
            [10] =>  
            [11] => w
            [12] => e
            [13] => b
            [14] =>  
            [15] => s
            [16] => c
            [17] => r
            [18] => i
            [19] => p
            [20] => t
            [21] => i
            [22] => n
            [23] => g
            [24] =>  
            [25] => l
            [26] => a
            [27] => n
            [28] => g
            [29] => u
            [30] => a
            [31] => g
            [32] => e
            [33] =>  
            [34] => o
            [35] => f
            [36] =>  
            [37] =>  
            [38] => c
            [39] => h
            [40] => o
            [41] => i
            [42] => c
            [43] => e
            [44] => .
            [45] =>  
        )

)

023 - Find a whitespace character
Array
(
    [0] => Array
        (
            [0] =>  
            [1] =>  
            [2] =>  
            [3] =>  
            [4] =>  
            [5] =>  
            [6] =>  
            [7] =>  
            [8] =>  
        )

)

024 - Find all character and left spaces
Array
(
    [0] => Array
        (
            [0] => P
            [1] => H
            [2] => P
            [3] => i
            [4] => s
            [5] => t
            [6] => h
            [7] => e
            [8] => w
            [9] => e
            [10] => b
            [11] => s
            [12] => c
            [13] => r
            [14] => i
            [15] => p
            [16] => t
            [17] => i
            [18] => n
            [19] => g
            [20] => l
            [21] => a
            [22] => n
            [23] => g
            [24] => u
            [25] => a
            [26] => g
            [27] => e
            [28] => o
            [29] => f
            [30] => 5
            [31] => 2
            [32] => 2
            [33] => c
            [34] => h
            [35] => o
            [36] => i
            [37] => c
            [38] => e
            [39] => .
            [40] => 8
            [41] => 2
            [42] => 5
        )

)

025 - specifies boundries, select only characters with space before and after
Array
(
    [0] => Array
        (
            [0] => i
        )

)

026 - specifies without boundries
Array
(
    [0] => Array
        (
            [0] => i
            [1] => i
            [2] => i
        )

)

027 - specifies boundries, search for word with space
Array
(
    [0] => Array
        (
            [0] => PHP
        )

)

028 - Meta characters(.) search word with start ph and return one more character after ph
Array
(
    [0] => Array
        (
            [0] => php
            [1] => php
            [2] => php
        )

)

029 - Meta characters(..) return 2 more characters after sc -------
Array
(
    [0] => Array
        (
            [0] => scrip
        )

)

030 - Meta characters(..) also put at the starting of the search string
Array
(
    [0] => Array
        (
            [0] => web
        )

)

031 - Special characters -- . ? ( [ + * $ | ^ --- can't use in patterns as usall, use backslash before character
Array
(
    [0] => Array
        (
            [0] => .
            [1] => .
        )

)

032 - above code for name with extension check
Array
(
    [0] => Array
        (
            [0] => file.txt
        )

)

033 - if the string one word is in next line , then we will use /n
Array
(
    [0] => Array
        (
        )

)

034 - Meta characters(\ n \ t \ v)
Array
(
    [0] => Array
        (
        )

)

035 - tab space
Array
(
    [0] => Array
        (
        )

)

036 - vertical tab
Array
(
    [0] => Array
        (
        )

)
<?php /* - 125-Regular-Expressions https://regex101.com/- */ echo "</br><h7 class='myheading'>125-Regular-Expressions https://regex101.com/</h7></br>"; // 001- serach PHP in string echo "</br><span class='sh1'>001- serach PHP in string</span></br>"; $string1 = "PHP is the web scripting language of choice."; $exp1 = preg_match("/PHP/", $string1); // return 0 or 1 if ($exp1) { echo "Found." . "<br>"; } else { echo "Not Found." . "<br>"; } /* 002 - Case Incensitive------- */ echo "</br><span class='sh1'>002 - Case Incensitive</span></br>"; $string2 = "PHP is the web scripting language of choice."; $exp2 = preg_match("/php/i", $string2); if ($exp2) { echo "Found." . "<br>"; } else { echo "Not Found." . "<br>"; } // 003 - match multiple word in string ,return an array echo "</br><span class='sh1'>003 - match multiple word in string ,return an array</span></br>"; $string3= "PHP is the web scripting php language of choice."; $exp3 = preg_match_all("/php/i", $string3, $ary3); echo "<pre>"; print_r($ary3); echo "</pre>"; /* 004 - Multiple word search in Array - */ echo "</br><span class='sh1'>004 - Multiple word search in Array </span></br>"; $string4= "PHP is the web scripting php language web of choice. web "; $exp4 = preg_match_all("/web|php/i", $string4, $ary4); echo "<pre>"; print_r($ary4); echo "</pre>"; /* 004-a - if need to print Only For One Value form array ------- */ echo "</br><span class='sh1'>004-a - if need to print Only For One Value form array </span></br>"; echo $ary4[0][0] . "<br>"; echo $ary4[0][1]; // 005 - many single characters search in one go echo "</br><span class='sh1'>005 - many single characters search in one go</span></br>"; $string5= "PHP is the web scripting php language web of choice. web "; $exp = preg_match_all("/w|o|t/i", $string5, $ary5); echo "<pre>"; print_r($ary5); echo "</pre>"; /*006 - Search Even Numbers - */ echo "</br><span class='sh1'>006 - Search Even Numbers</span></br>"; $string6 = "PHP is the web scripting language of 522 choice. 825"; $exp = preg_match("/522/i", $string6, $ary6); echo "<pre>"; print_r($ary6); echo "</pre>"; /*007 - Character Set, search multiple value in string without using pipe sign------- */ echo "</br><span class='sh1'>007 - Character Set, search multiple value in string without using pipe sign</span></br>"; $string7 = "PHP is the web scripting language of 522 choice. 825"; $exp7 = preg_match_all("/[w]/i", $string7, $ary7); // can be used for multiple characters echo "<pre>"; print_r($ary7); echo "</pre>"; /*008 - search all except the input chracter by user, like = not search = ^wot ------- */ echo "</br><span class='sh1'>008 - search all except the input chracter by user, like = not search = ^wot </span></br>"; $string8 = "PHP is the web scripting language of 522 choice. 825"; $exp8 = preg_match_all("/[^wot]/i", $string8, $ary8); //----- not included w,o,t, can be used for number also echo "<pre>"; print_r($ary8); echo "</pre>"; /*009 - Range, like = search all characters from a to c------- */ echo "</br><span class='sh1'>009 - Range, like = search all characters from a to c</span></br>"; $string9 = "PHP is the web scripting language of 522 choice. 825"; $exp9 = preg_match_all("/[a-c]/i", $string9, $array9); // can be used for number also echo "<pre>"; print_r($array9); echo "</pre>"; /*010 - Range upper and lower search without using italic character = i ------- */ echo "</br><span class='sh1'>010 - Range upper and lower search without using italic character = i</span></br>"; $string10 = "PHP is the web scripting language of 522 choice. 825"; $exp10 = preg_match_all("/[a-kA-K]/", $string10, $array10); echo "<pre>"; print_r($array10); echo "</pre>"; /*011 - search number and charcter without using pipe sign in one go------- */ echo "</br><span class='sh1'>011 - search number and charcter without using pipe sign in one go</span></br>"; $string11 = "PHP is the web scripting language of 522 choice. 825"; $exp11 = preg_match_all("/[0-9a-d]/", $string11, $array11); echo "<pre>"; print_r($array11); echo "</pre>"; /*012 - search same character name with end defferent , like = search file2 in string (file1 file2 file3)------- */ echo "</br><span class='sh1'>012 - search same character name with end defferent , like = search file2 in string (file1 file2 file3)</span></br>"; $string12 = "file1 file2 file3 file# file? file5 file6"; $exp12 = preg_match_all("/file[123]/", $string12, $array12); echo "<pre>"; print_r($array12); echo "</pre>"; /*013 - search end different with range ------- */ echo "</br><span class='sh1'>013 - search end different with range </span></br>"; $string13 = "file1 file2 file3 file# file? file5 file6"; $exp13 = preg_match_all("/file[0-9]/", $string13, $array13); // can be used with not = ^ echo "<pre>"; print_r($array13); echo "</pre>"; /*014 - search above with numbers */ echo "</br><span class='sh1'>014 - search above with numbers </span></br>"; $string14= "2015 2016 2017 2018"; $exp14 = preg_match_all("/201[0-9]/", $string14, $array14); echo "<pre>"; print_r($array14); echo "</pre>"; /*015 - search word which, start, end & in middle must have user defined characters ------- */ echo "</br><span class='sh1'>015 - search word whihc start , end and in middle must have user defined characters</span></br>"; $string15 = "PHP is the web scripting language of 522 choice. 825"; $exp15 = preg_match_all("/w[abcdef]b/", $string15, $array15); echo "<pre>"; print_r($array15); echo "</pre>"; /*017 - above code with range fucntion in middle ------- */ echo "</br><span class='sh1'>017 - above code with range fucntion in middle </span></br>"; $string17 = "PHP is the web scripting language of 522 choice. 825"; $exp17 = preg_match_all("/w[a-j]b/", $string17, $array17); echo "<pre>"; print_r($array17); echo "</pre>"; /*018 - above code with characters------- */ echo "</br><span class='sh1'>018 - above code with characters</span></br>"; $string18= "bat cat mat rat"; $exp18 = preg_match_all("/[bc]at/", $string18, $array18); //------- match bat,cat echo "<pre>"; print_r($array18); echo "</pre>"; /*019 - Meta characters, select all chracter excepts . and - ------- */ echo "</br><span class='sh1'>019 - Meta characters, select all chracter excepts . and -</span></br>"; $string19 = "PHP is the web scripting language of 522 choice. 825"; $exp19 = preg_match_all("/\w/", $string19, $array19); //--- Matches all lower and upper case letters, digits and underscore. echo "<pre>"; print_r($array19); echo "</pre>"; /*020 - Capital W - all spaces and other sign, leave the numbers and characters------- */ echo "</br><span class='sh1'>020 - Capital W - all spaces and other sign, leave the numbers and characters</span></br>"; $string20 = "PHP is the web scripting language of 522 choice. 825"; $exp20 = preg_match_all("/\W/", $string20, $array20); //--- echo "<pre>"; print_r($array20); echo "</pre>"; /*021 - Matches any digit from 0 to 9.------- */ echo "</br><span class='sh1'>021 - Matches any digit from 0 to 9</span></br>"; $string21 = "PHP is the web scripting language of 522 choice. 825"; $exp21 = preg_match_all("/\d/", $string21, $array21); //--- echo "<pre>"; print_r($array21); echo "</pre>"; /*022 - Capital D -- return all char, sign except numbers------- */ echo "</br><span class='sh1'>022 - Capital D -- return all char, sign except numbers</span></br>"; $string22 = "PHP is the web scripting language of 522 choice. 825"; $exp22 = preg_match_all("/\D/", $string22, $array22); //--- echo "<pre>"; print_r($array22); echo "</pre>"; /*023 - Find a whitespace character------- */ echo "</br><span class='sh1'>023 - Find a whitespace character</span></br>"; $string23 = "PHP is the web scripting language of 522 choice. 825"; $exp23 = preg_match_all("/\s/i", $string23, $array23); //--- echo "<pre>"; print_r($array23); echo "</pre>"; /*024 - Find all character and left spaces ------- */ echo "</br><span class='sh1'>024 - Find all character and left spaces </span></br>"; $string24 = "PHP is the web scripting language of 522 choice. 825"; $exp24 = preg_match_all("/\S/i", $string24, $array24); //--- echo "<pre>"; print_r($array24); echo "</pre>"; /*025 - specifies boundries, select only characters with space before and after------- */ echo "</br><span class='sh1'>025 - specifies boundries, select only characters with space before and after</span></br>"; $string25= "PHP is the web i scripting language phpwow 522 of chooice."; $exp25 = preg_match_all("/\bi\b/i", $string25, $array25); //--- echo "<pre>"; print_r($array25); echo "</pre>"; /*026 - specifies without boundries------- */ echo "</br><span class='sh1'>026 - specifies without boundries</span></br>"; $string26= "PHP is the web i scripting language phpwow 522 of chooice."; $exp26 = preg_match_all("/\Bi\B/i", $string26, $array26); //--- echo "<pre>"; print_r($array26); echo "</pre>"; /*027 - specifies boundries, search for word with space ------- */ echo "</br><span class='sh1'>027 - specifies boundries, search for word with space</span></br>"; $string27= "PHP is the web i scripting language phpwow 522 of chooice."; $exp27 = preg_match_all("/\bphp\b/i", $string27, $array27); echo "<pre>"; print_r($array27); echo "</pre>"; /*028 - Meta characters(.) search word with start ph and return one more character after ph ------- */ echo "</br><span class='sh1'>028 - Meta characters(.) search word with start ph and return one more character after ph </span></br>"; $string28= "PHP is thephp web i scripting php language phpwow 522 of chooice."; $exp28 = preg_match_all("/ph./", $string28, $array28); //--- It denotes almost any single character. echo "<pre>"; print_r($array28); echo "</pre>"; /*029 - Meta characters(..) return 2 more characters after sc ------- */ echo "</br><span class='sh1'>029 - Meta characters(..) return 2 more characters after sc ------- </span></br>"; $string29= "PHP is thephp web i scripting php language phpwow 522 of chooice."; $exp29 = preg_match_all("/sc.../", $string29, $array29); echo "<pre>"; print_r($array29); echo "</pre>"; /*030 - Meta characters(..) also put at the starting of the search string ------- */ echo "</br><span class='sh1'>030 - Meta characters(..) also put at the starting of the search string</span></br>"; $string30= "PHP is thephp web i scripting php language phpwow 522 of chooice."; $exp30 = preg_match_all("/.eb/", $string30, $array30); echo "<pre>"; print_r($array30); echo "</pre>"; /*031 - Special characters -- . ? ( [ + * $ | ^ --- can't use in patterns as usall, use backslash before character */ echo "</br><span class='sh1'>031 - Special characters -- . ? ( [ + * $ | ^ --- can't use in patterns as usall, use backslash before character</span></br>"; $string31= "PHP is thephp web i . scripting php language phpwow 522 of chooice."; $exp31 = preg_match_all("/\./", $string31, $array31); //--- echo "<pre>"; print_r($array31); echo "</pre>"; /*032 - above code for name with extension check like return = file.txt------- */ echo "</br><span class='sh1'>032 - above code for name with extension check </span></br>"; $string32= "file.txt file2txt file#txt file txt"; $exp32 = preg_match_all("/file\.txt/", $string32, $array32); echo "<pre>"; print_r($array32); echo "</pre>"; /*033 - if the string one word is in next line , then we will use /n------- */ echo "</br><span class='sh1'>033 - if the string one word is in next line , then we will use /n</span></br>"; $string33= "This is a car"; $exp33 = preg_match_all("/This is a .car/", $string33, $array33); echo "<pre>"; print_r($array33); echo "</pre>"; /*034 - Meta characters(\n, \t, \v)*/ echo "</br><span class='sh1'>034 - Meta characters(\ n \ t \ v)</span></br>"; $string34= "This is a car "; $exp34 = preg_match_all("/This is a\ncar/i", $string34, $array34); //<--- \n -- newline echo "<pre>"; print_r($array34); echo "</pre>"; /*035 - tab space ,shwowing empty array , but working in regex101.com------- */ echo "</br><span class='sh1'>035 - tab space </span></br>"; $string035= "This is a car"; //--- add tab before car $exp035 = preg_match_all("/This is a\tcar/i", $string035, $array035); //<--- \t -- tab echo "<pre>"; print_r($array035); echo "</pre>"; /*036 - vertical tab ,shwowing empty array , but working in regex101.com ------- */ echo "</br><span class='sh1'>036 - vertical tab </span></br>"; $string036= "This is a car another test"; $exp036 = preg_match_all("/This is a\vcar/i", $string036, $array036); //This is a\ncar another \vtest <----- \v -- vertical tab echo "<pre>"; print_r($array036); echo "</pre>"; ?>