Trying to find a specific tag in a given string with newline as below:

exp( 2pi + 1 ) - [--||value1||--]^3
round(455.6172,0)
[--||value2||455, 456, 457||--]%%3 == 0 ;

I try to use the following code to search the [--|| ||--] tag format, and it works:

preg_match("/\[--\|([\*_a-z0-9A-Z.\|])+\|--\]/", $sTagTxt)

However, if my string contain asterisk (*) as below, it won't work:

exp( 2[B][SIZE="5"][COLOR="Red"]*[/COLOR][/SIZE][/B]pi + 1 ) - [--||value1||--]^3
round(455.6172,0)
[--||value2||455, 456, 457||--]%%3 == 0 ;

Should I replace the * with other character or can escape at preg_match pattern?

Thanks.

    Escaping * as part of a character class does nothing. Escaping | as part of a character class does nothing.

    And since I get no difference at all regarding wether the string contains 2*pi or just 2pi, I'd say both patterns work the same, which they should.

    # Removed escaping of * and | in the character class, otherwise identical to yours.
    # And escaping or not escaping them makes no difference.
    $p = "#\[--\|([*_a-z0-9A-Z.|])+\|--\]#";
    
    
    $s1 = "exp( 2pi + 1 ) - [--||value1||--]^3
    round(455.6172,0)
    [--||value2||455, 456, 457||--]%%3 == 0 ;";
    
    $s2 = "exp( 2*pi + 1 ) - [--||value1||--]^3
    round(455.6172,0)
    [--||value2||455, 456, 457||--]%%3 == 0 ;";
    
    echo 's1'.PHP_EOL;
    if (preg_match($p, $s1, $m))
    {
    	print_r($m);
    }
    echo PHP_EOL.'s2'.PHP_EOL;
    if (preg_match($p, $s2, $m))
    {
    	print_r($m);
    }
    

    Result

    s1
    Array
    (
        [0] => [--||value1||--]
        [1] => |
    )
    
    s2
    Array
    (
        [0] => [--||value1||--]
        [1] => |
    )
    
      Write a Reply...