Search code examples
phppreg-matchpreg-split

php preg_match between Combination of square brackets and brackets


i want to use preg_match to find text between [{}] for example: $varx = "[{xx}]";

final output will be $match = 'xx';

another example $varx = "bla bla [{yy}] bla bla";

final output will be something like this $match = 'yy';

in other words it strips out bracket. i'm still confusing with regular expression but found that sometimes preg match is more simple solution. searching other example but not meet my need.


Solution

  • This one should work for you:

    preg_match('/\[\{([^\]\}]+)\}\]/', $varx, $match);