Regular Expression with php Error

i have the following html structure :

<div data-provincia="mi" data-nazione="it" ecc...

I'm trying to take "mi" with preg_match function. This is my code :

$pattern = '/data-provincia=*"[a-zA-Z]*"/';

I think that the code is right but it doesn't match with anything. Where i'm wrong? Thanks.


  • You might want to use the quantifier + (1 or more) next to the character class between brackets, and remove the first star. Also added a subtpattern for you to get exactly the part you want. Give it a try :

    $pattern = '/data-provincia="([a-zA-Z]+)"/';
    echo $provincia[1];