Search code examples
phpregexplaceholdertext-parsing

Extract data from a square braced placeholder


I want to form a pattern to match the word "Jason" in the following string:

[LASTUSER=Jason;22]

Solution

  • The following matches the name and the following number:

    preg_match('/\[LASTUSER=([^;]*);(\d+)\]/', $str, $matches);