php - Replace all the ".net clr" in user agent -


i learning regex , testing string lookup/replacement on user agent.

i have few user agent with:

  • .net clr 11432
  • .net clr 2.0.2648
  • .net clr 1.0.1369
  • .net clr 2.0.90283

i can replace ".net clr \d" no work properly.

  $ua = 'mozilla/4.0 (compatible; msie 7.0; windows nt 4.1; .net clr 12858)';    $r = preg_replace('/.net clr \d/i', '', $ua);    var_dump($r); 

and get:

mozilla/4.0 (compatible; msie 7.0; windows nt 4.1; 2858; .0.6143)

clearly missing something, what?

thanks

your regex doesn't adhere decimal point of version number, that's why it's matching until .. change regex this:

$r = preg_replace('/\.net clr [\d\.]+/i', '', $ua); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -