Ethan Rosenberg | 27 Jul 2012 19:07
Picon
Favicon

Regex

Dear list -

I've tried everything  and am still stuck.

A regex that will accept numbers, letters, comma, period and no other 
characters

Thanks.

Ethan Rosenberg

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Simon Dániel | 27 Jul 2012 19:14
Picon

Re: Regex

#[0-9a-zA-Z,.]#

2012/7/27 Ethan Rosenberg <ethros <at> earthlink.net>

> Dear list -
>
> I've tried everything  and am still stuck.
>
> A regex that will accept numbers, letters, comma, period and no other
> characters
>
> Thanks.
>
> Ethan Rosenberg
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Ashley Sheridan | 27 Jul 2012 19:16
Picon

Re: Regex


"Simon Dániel" <simondani91 <at> gmail.com> wrote:

>#[0-9a-zA-Z,\.]#
>

You should escape out that period as it will match any character otherwise.
Thanks,
Ash
http://ashleysheridan.co.uk

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

David Harkness | 27 Jul 2012 19:40

Re: Regex

On Fri, Jul 27, 2012 at 10:16 AM, Ashley Sheridan
<ash <at> ashleysheridan.co.uk>wrote:

> "Simon Dániel" <simondani91 <at> gmail.com> wrote:
>
> >#[0-9a-zA-Z,\.]#
>
> You should escape out that period as it will match any character otherwise
>

The dot only matches a period inside a character class [...].

David
shiplu | 27 Jul 2012 19:54
Picon
Gravatar

Re: Regex

>#[0-9a-zA-Z,\.]#
> >
>
> You should escape out that period as it will match any character otherwise.
> Thanks,
> Ash
>

Ash, Thats not true. In character class only meta-characters are \ ^ - [
and ]. This is the rule of PCRE (see
http://www.pcre.org/pcre.txt<http://www.pcre.org/pcre.txt#CHARACTERS%20AND%20METACHARACTERS>).
I assume we are talking about pcre as everybody used delimiter here which
is required in pcre.

--

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader
Sebastian Krebs | 27 Jul 2012 21:46
Picon
Gravatar

Re: Regex

Am 27.07.2012 19:54, schrieb shiplu:
>> #[0-9a-zA-Z,\.]#
>>>
>>
>> You should escape out that period as it will match any character otherwise.
>> Thanks,
>> Ash
>>
>
> Ash, Thats not true. In character class only meta-characters are \ ^ - [

And the dash only when it's not the first, or the last in the class.

> and ]. This is the rule of PCRE (see
> http://www.pcre.org/pcre.txt<http://www.pcre.org/pcre.txt#CHARACTERS%20AND%20METACHARACTERS>).
> I assume we are talking about pcre as everybody used delimiter here which
> is required in pcre.
>

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Stuart Dallas | 27 Jul 2012 19:16
Gravatar

Re: Regex

On 27 Jul 2012, at 18:07, Ethan Rosenberg <ethros <at> earthlink.net> wrote:

> I've tried everything  and am still stuck.
> 
> A regex that will accept numbers, letters, comma, period and no other characters

/^[0-9a-zA-Z,\.]+$/

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Sebastian Krebs | 27 Jul 2012 19:16
Picon
Gravatar

Re: Regex

Hi,

Am 27.07.2012 19:07, schrieb Ethan Rosenberg:
> Dear list -
>
> I've tried everything  and am still stuck.
>
> A regex that will accept numbers, letters, comma, period and no other
> characters

This?

/^[0-9a-zA-Z,.]$/

Regards,
Sebastian

>
> Thanks.
>
> Ethan Rosenberg
>
>
>

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

(Continue reading)

Al | 27 Jul 2012 20:43
Favicon

Re: Regex


On 7/27/2012 1:07 PM, Ethan Rosenberg wrote:
> Dear list -
>
> I've tried everything  and am still stuck.
>
> A regex that will accept numbers, letters, comma, period and no other characters
>
> Thanks.
>
> Ethan Rosenberg
>
>

"%[\w\d,.]%"

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

David Harkness | 27 Jul 2012 20:56

Re: Re: Regex

On Fri, Jul 27, 2012 at 11:43 AM, Al <news <at> ridersite.org> wrote:

> "%[\w\d,.]%"
>

"\w" will match digits so "\d" isn't necessary, but it will also match
underscores which isn't desired.

David
Al | 27 Jul 2012 21:28
Favicon

Re: Re: Regex


On 7/27/2012 2:56 PM, David Harkness wrote:
> On Fri, Jul 27, 2012 at 11:43 AM, Al <news <at> ridersite.org> wrote:
>
>> "%[\w\d,.]%"
>>
>
> "\w" will match digits so "\d" isn't necessary, but it will also match
> underscores which isn't desired.
>
> David
>
You're correct, I forgot about the darn _ and \w includes digits

So, how's about this.
"%(?!_)[\w,.]%"

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Gmane