Page 1 of 1

Quick Regex problem

Posted: Sun Jul 03, 2005 10:57 pm
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.

Posted: Mon Jul 04, 2005 2:12 am
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);