[Solved] Regex expression symbol without space


I would use: ~\{\{([^}]+?)\}\}~
and accessing array depends on your language!

[EDIT] add explanations

  • ~: delimiter
  • \{\{, \}\}~: match characters literally. Should be
    escaped.
  • [^}]: match anything inside {{}} until a }
  • +: repeat
    pattern multiple times (for multiple characters)
  • ?: is for ‘lazy’
    to match as few times as possible.
  • (): is to capture

🙂

[EDIT] add PHP code sample for matching illustration:

<?php
    $string= "{{test1}}{{test2}}{{test3}}";

    if (preg_match_all("~\{\{([^}]+?)\}\}~s", $string, $matches))
    {
        print_r(array($matches));
        // Do what you want
    }
    ?>

will output this:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => {{test1}}
                    [1] => {{test2}}
                    [2] => {{test3}}
                )

            [1] => Array
                (
                    [0] => test1
                    [1] => test2
                    [2] => test3
                )

        )

)

0

solved Regex expression symbol without space