Solved

Regex question

Posted on 2006-06-19
3
211 Views
Last Modified: 2008-03-04

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
Comment
Question by:dwax
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16934661
preg_match('/(&nbsp|\s)/', $test, $matches);

-r-
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 50 total points
ID: 16934664
I forgot to include the semicolon:

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

-r-
0
 

Author Comment

by:dwax
ID: 16934727

Thanks!
You just saved my keyboard from flying out the window...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now