PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Variables names

Find variables names.
 
$str = '$a, $_b, $a10, $1, $-';

preg_match_all('/[$][a-zA-Z_][A-Za-z_0-9]*/', $str, $matches); 
    // not allowed ($1, $-)

var_dump($matches[0]);     // $a, $_b, $a10
Double Quotes    (2/2)

Double quotes

Match strings within double-quotes
 
$str = 'A string with "stringA" and "stringB" in it';

preg_match_all('/ (?x) " ([^"]+) " /', $str, $matches); 
           // ?x (ignore spaces for readability)
           // readability modifier doesn't work with double quotes

echo join(", ", $matches[1]); // outputs: stringA, stringB

Questions    
Pattern match

        A B C D E F
🔔
1/2