Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Regex question


Hi,

Struggling with the following, there's an adress, i would like to preg_match either an   or an empty space ([\s] ?) as both can be present.

Streetname City
Streetname City

So doing something like this:
preg_match('/ /s',$test,$matches);      
$show = $matches[0];      
echo "$show";

Works for the first sentence, but:
How can i catch both possibilties in one?

Any help would be great!

      
0
dwax
Asked:
dwax
  • 2
1 Solution
 
RoonaanCommented:
preg_match('/(&nbsp|\s)/', $test, $matches);

-r-
0
 
RoonaanCommented:
I forgot to include the semicolon:

preg_match('/( |\s)/', $test, $matches);

-r-
0
 
dwaxAuthor Commented:

Thanks!
You just saved my keyboard from flying out the window...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now