Solved

Regex question

Posted on 2006-06-19
3
210 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
Comment Utility
preg_match('/(&nbsp|\s)/', $test, $matches);

-r-
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 50 total points
Comment Utility
I forgot to include the semicolon:

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

-r-
0
 

Author Comment

by:dwax
Comment Utility

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

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now