Mark
Mark

Reputation: 3859

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]

Upvotes: 2

Views: 84

Answers (2)

Emre Yazici
Emre Yazici

Reputation: 10174

$pattern = '%\\[LASTUSER=([^;]+?);[0-9]+\\]%i';
if(preg_match($pattern, $str, $matches)) {
    $user = $matches[1];
}

Upvotes: 2

user142162
user142162

Reputation:

The following matches the name and the following number:

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

Upvotes: 3

Related Questions