Solved

Regex question

Posted on 2006-06-19
3
213 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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 …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

809 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