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:
- ag055.ma - magnum (want return ma)
- wi460.16 - (want return 16)
- 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
Post a Comment