PHP Regex pulling text after period and before space -


i'm attempting pull part out of different varying strings, , having hard time getting correct regex so. here few examples of trying pull from:

  1. ag055.ma - magnum (want return ma)
  2. wi460.16 - (want return 16)
  3. ag055.qb (want return qb)

so basically, want pull characters after period, before space. nothing else before or after. can give me hand getting correct regex?

this should work:

<?php preg_match( '/\.([^ ]+)/', $text, $matches );  print_r( $matches ); ?> 

output:

array (     [0] => .ma     [1] => ma )  array (     [0] => .16     [1] => 16 )  array (     [0] => .qb     [1] => qb ) 

the regex saying find . character, characters after not space character. + makes return matches there non-space character after dot.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -