Quick Regex problem

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
MathewByrne
Forum Commoner
Posts: 38
Joined: Sat Mar 27, 2004 9:49 pm
Location: Australia

Quick Regex problem

Post by MathewByrne »

Hi just needed a Regex expression for a comma seperated list of postcodes (Australian so 4 digits).

The following are valid:

Code: Select all

3554, 2000, 5098
3100
5444,8875,1233
The following are invalid:

Code: Select all

3554, 2000,

5444,50000
Thanks ahead.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You say comma separated but line 2 in the good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
his would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
d{4}\b/', $content, $matches);


If the comma is required,

[phmma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
rated but line 2 in the good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
o this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\be good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
rated but line 2 in the good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
[/php:1:f3('/\b\d{4},/', $content, $matches);
ood example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
at.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

pregcontent, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
ould work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
rated but line 2 in the good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},rated but line 2 in the good example has no comma so this would work for that.

Code: Select all

preg_match_all('/\b\d{4}\b/', $content, $matches);
If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
preg_match_all('/\b\d{4}\b/', $content, $matches);


If the comma is required,

Code: Select all

preg_match_all('/\b\d{4},/', $content, $matches);
Post Reply