Newbie needs help with ereg regular expression

Hi,

I have to repost this to restate the question. No disrespect to the original
reply.

Please can someone help regarding providing a regular expression for entering
a set of characters with letters, numbers, periods (.), hyphens (-), or
underscores (_) only.

I need to do this using ereg

I've got as far as this but it doesn't quite work:

$pattern="^([a-z0-9.-_]{0,30})$";
if(ereg($pattern,$_SESSION['id']))
....


Thank you in advance.

Kind regards,

Raj (newbie)
raj [ Fr, 16 Februar 2007 12:55 ] [ ID #1631502 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

As a matter of interest, why does it have to be done using ereg rather
than say, preg_match?
Captain Paralytic [ Fr, 16 Februar 2007 12:59 ] [ ID #1631503 ]

Re: Newbie needs help with ereg regular expression

On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
(in article <1171627167.523089.186830 [at] m58g2000cwm.googlegroups.com>):

> On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for
>> entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> As a matter of interest, why does it have to be done using ereg rather
> than say, preg_match?
>

It's for 2 reasons

1. Be consistent throughout the site
2. I will disable preg_match and some other unused functions.

Any help with providing the ereg answer would be greatly appreciated.

Kind regards,

Raj
raj [ Fr, 16 Februar 2007 13:06 ] [ ID #1631504 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 12:06, raj <r... [at] nospam.com> wrote:
> On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
> (in article <1171627167.523089.186... [at] m58g2000cwm.googlegroups.com>):
>
>
>
>
>
> > On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> >> Hi,
>
> >> I have to repost this to restate the question. No disrespect to the original
> >> reply.
>
> >> Please can someone help regarding providing a regular expression for
> >> entering
> >> a set of characters with letters, numbers, periods (.), hyphens (-), or
> >> underscores (_) only.
>
> >> I need to do this using ereg
>
> >> I've got as far as this but it doesn't quite work:
>
> >> $pattern="^([a-z0-9.-_]{0,30})$";
> >> if(ereg($pattern,$_SESSION['id']))
> >> ...
>
> >> Thank you in advance.
>
> >> Kind regards,
>
> >> Raj (newbie)
>
> > As a matter of interest, why does it have to be done using ereg rather
> > than say, preg_match?
>
> It's for 2 reasons
>
> 1. Be consistent throughout the site
> 2. I will disable preg_match and some other unused functions.
>
> Any help with providing the ereg answer would be greatly appreciated.
>
> Kind regards,
>
> Raj- Hide quoted text -
>
> - Show quoted text -

Sheesh, what terrible reasons. the php manual itself advises the use
of perg_match over ereg for efficiency.
Captain Paralytic [ Fr, 16 Februar 2007 13:15 ] [ ID #1631505 ]

Re: Newbie needs help with ereg regular expression

Post removed (X-No-Archive: yes)
Notifier Deamon [ Fr, 16 Februar 2007 19:08 ] [ ID #1631514 ]

Re: Newbie needs help with ereg regular expression

On Feb 16, 6:08 pm, Tom <t... [at] to.com> wrote:
> On Fri, 16 Feb 2007 11:55:02 +0000, raj wrote...
>
> >Hi,
>
> >I have to repost this to restate the question. No disrespect to the original
> >reply.
>
> >Please can someone help regarding providing a regular expression for entering
> >a set of characters with letters, numbers, periods (.), hyphens (-), or
> >underscores (_) only.
>
> >I need to do this using ereg
>
> >I've got as far as this but it doesn't quite work:
>
> >$pattern="^([a-z0-9.-_]{0,30})$";
> >if(ereg($pattern,$_SESSION['id']))
> >...
>
> >Thank you in advance.
>
> >Kind regards,
>
> >Raj (newbie)
>
> Normally with "preg" I need to put the hyphen last, otherwise it may confuse a
> literal hyphen with the special character. Such as the hyphens you're using to
> specify the range of letters and numbers. The same may apply to the function
> you're trying to use.
>
> Tom
> --
> Newsguy.com - Basic Accounts $39.95 / 12 months
> 75+ days of Binary and Text Retention!
> Higher levels of article completion!
> Broader coverage of newsgroups

If by $_SESSION['id'] you mean the standard PHPSESSID, it has 32
characters, no more no less, be default.
If not then Tom is right, hyphen last.
shimmyshack [ Fr, 16 Februar 2007 20:13 ] [ ID #1631515 ]

Re: Newbie needs help with ereg regular expression

On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

So you have written

$pattern="^([a-z0-9.-_]{0,30})$"

match a to z, 0 to 9, "." to '_' starting at the beginning of the line
and ending at the end of the line with a maximum of 30 character and a
minimum of 0 character.

they are right about preg_match. which all it means is you need to
wright you regex slightly differently and you can do fancy things if
you wanted to.

http://www.perl.com/doc/manual/html/pod/perlre.html

so

"/^[\w\.\-]{0,30}$/
or
"/^[a-zA-Z0-9\_\.\-]{0,30}$/
which is the same thing just longer to write out
and these are generally case sensitive remember so 'a' != 'A' (hence a-
zA-Z and not just a-z)


try that or at lest it should give you a good direction
mvandenb [ Fr, 16 Februar 2007 22:08 ] [ ID #1631516 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

As a matter of interest, why does it have to be done using ereg rather
than say, preg_match?
Captain Paralytic [ Fr, 16 Februar 2007 12:59 ] [ ID #1631526 ]

Re: Newbie needs help with ereg regular expression

On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
(in article <1171627167.523089.186830 [at] m58g2000cwm.googlegroups.com>):

> On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for
>> entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> As a matter of interest, why does it have to be done using ereg rather
> than say, preg_match?
>

It's for 2 reasons

1. Be consistent throughout the site
2. I will disable preg_match and some other unused functions.

Any help with providing the ereg answer would be greatly appreciated.

Kind regards,

Raj
raj [ Fr, 16 Februar 2007 13:06 ] [ ID #1631527 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 12:06, raj <r... [at] nospam.com> wrote:
> On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
> (in article <1171627167.523089.186... [at] m58g2000cwm.googlegroups.com>):
>
>
>
>
>
> > On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> >> Hi,
>
> >> I have to repost this to restate the question. No disrespect to the original
> >> reply.
>
> >> Please can someone help regarding providing a regular expression for
> >> entering
> >> a set of characters with letters, numbers, periods (.), hyphens (-), or
> >> underscores (_) only.
>
> >> I need to do this using ereg
>
> >> I've got as far as this but it doesn't quite work:
>
> >> $pattern="^([a-z0-9.-_]{0,30})$";
> >> if(ereg($pattern,$_SESSION['id']))
> >> ...
>
> >> Thank you in advance.
>
> >> Kind regards,
>
> >> Raj (newbie)
>
> > As a matter of interest, why does it have to be done using ereg rather
> > than say, preg_match?
>
> It's for 2 reasons
>
> 1. Be consistent throughout the site
> 2. I will disable preg_match and some other unused functions.
>
> Any help with providing the ereg answer would be greatly appreciated.
>
> Kind regards,
>
> Raj- Hide quoted text -
>
> - Show quoted text -

Sheesh, what terrible reasons. the php manual itself advises the use
of perg_match over ereg for efficiency.
Captain Paralytic [ Fr, 16 Februar 2007 13:15 ] [ ID #1631528 ]

Re: Newbie needs help with ereg regular expression

On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

So you have written

$pattern="^([a-z0-9.-_]{0,30})$"

match a to z, 0 to 9, "." to '_' starting at the beginning of the line
and ending at the end of the line with a maximum of 30 character and a
minimum of 0 character.

they are right about preg_match. which all it means is you need to
wright you regex slightly differently and you can do fancy things if
you wanted to.

http://www.perl.com/doc/manual/html/pod/perlre.html

so

"/^[\w\.\-]{0,30}$/
or
"/^[a-zA-Z0-9\_\.\-]{0,30}$/
which is the same thing just longer to write out
and these are generally case sensitive remember so 'a' != 'A' (hence a-
zA-Z and not just a-z)


try that or at lest it should give you a good direction
mvandenb [ Fr, 16 Februar 2007 22:08 ] [ ID #1631536 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

As a matter of interest, why does it have to be done using ereg rather
than say, preg_match?
Captain Paralytic [ Fr, 16 Februar 2007 12:59 ] [ ID #1631631 ]

Re: Newbie needs help with ereg regular expression

On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
(in article <1171627167.523089.186830 [at] m58g2000cwm.googlegroups.com>):

> On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for
>> entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> As a matter of interest, why does it have to be done using ereg rather
> than say, preg_match?
>

It's for 2 reasons

1. Be consistent throughout the site
2. I will disable preg_match and some other unused functions.

Any help with providing the ereg answer would be greatly appreciated.

Kind regards,

Raj
raj [ Fr, 16 Februar 2007 13:06 ] [ ID #1631633 ]

Re: Newbie needs help with ereg regular expression

On 16 Feb, 12:06, raj <r... [at] nospam.com> wrote:
> On Fri, 16 Feb 2007 11:59:27 +0000, Captain Paralytic wrote
> (in article <1171627167.523089.186... [at] m58g2000cwm.googlegroups.com>):
>
>
>
>
>
> > On 16 Feb, 11:55, raj <r... [at] nospam.com> wrote:
> >> Hi,
>
> >> I have to repost this to restate the question. No disrespect to the original
> >> reply.
>
> >> Please can someone help regarding providing a regular expression for
> >> entering
> >> a set of characters with letters, numbers, periods (.), hyphens (-), or
> >> underscores (_) only.
>
> >> I need to do this using ereg
>
> >> I've got as far as this but it doesn't quite work:
>
> >> $pattern="^([a-z0-9.-_]{0,30})$";
> >> if(ereg($pattern,$_SESSION['id']))
> >> ...
>
> >> Thank you in advance.
>
> >> Kind regards,
>
> >> Raj (newbie)
>
> > As a matter of interest, why does it have to be done using ereg rather
> > than say, preg_match?
>
> It's for 2 reasons
>
> 1. Be consistent throughout the site
> 2. I will disable preg_match and some other unused functions.
>
> Any help with providing the ereg answer would be greatly appreciated.
>
> Kind regards,
>
> Raj- Hide quoted text -
>
> - Show quoted text -

Sheesh, what terrible reasons. the php manual itself advises the use
of perg_match over ereg for efficiency.
Captain Paralytic [ Fr, 16 Februar 2007 13:15 ] [ ID #1631634 ]

Re: Newbie needs help with ereg regular expression

On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have to repost this to restate the question. No disrespect to the original
> reply.
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I need to do this using ereg
>
> I've got as far as this but it doesn't quite work:
>
> $pattern="^([a-z0-9.-_]{0,30})$";
> if(ereg($pattern,$_SESSION['id']))
> ...
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)

So you have written

$pattern="^([a-z0-9.-_]{0,30})$"

match a to z, 0 to 9, "." to '_' starting at the beginning of the line
and ending at the end of the line with a maximum of 30 character and a
minimum of 0 character.

they are right about preg_match. which all it means is you need to
wright you regex slightly differently and you can do fancy things if
you wanted to.

http://www.perl.com/doc/manual/html/pod/perlre.html

so

"/^[\w\.\-]{0,30}$/
or
"/^[a-zA-Z0-9\_\.\-]{0,30}$/
which is the same thing just longer to write out
and these are generally case sensitive remember so 'a' != 'A' (hence a-
zA-Z and not just a-z)


try that or at lest it should give you a good direction
mvandenb [ Fr, 16 Februar 2007 22:08 ] [ ID #1631684 ]

Re: Newbie needs help with ereg regular expression

mvandenb [at] gmail.com wrote:
> On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> So you have written
>
> $pattern="^([a-z0-9.-_]{0,30})$"
>
> match a to z, 0 to 9, "." to '_' starting at the beginning of the line
> and ending at the end of the line with a maximum of 30 character and a
> minimum of 0 character.
>
> they are right about preg_match. which all it means is you need to
> wright you regex slightly differently and you can do fancy things if
> you wanted to.
>
> http://www.perl.com/doc/manual/html/pod/perlre.html
>
> so
>
> "/^[\w\.\-]{0,30}$/
> or
> "/^[a-zA-Z0-9\_\.\-]{0,30}$/
> which is the same thing just longer to write out
> and these are generally case sensitive remember so 'a' != 'A' (hence a-
> zA-Z and not just a-z)
>
>
> try that or at lest it should give you a good direction

You should not escape dots in character classes, as they are not meta
characters in that context. Also, if - (dash) is the last character in
the character class, it also does not need to be escaped. Using \w
would be better, as it would allow for more characters with regard to
locale.

[at] OP: PCRE regex are much more efficient than the POSIX flavor. If your
worries are over consistency, then stop using POSIX regex. :-) As
already mentioned here, even the PHP documentation team is
recommending PCRE preg_* functions over ereg_* functions at all turns.

Also, you already have a pattern, have you tried testing it? If you
have a specific problem, ask a specific question.

--
Curtis
Curtis [ Sa, 17 Februar 2007 07:09 ] [ ID #1632403 ]

Re: Newbie needs help with ereg regular expression

mvandenb [at] gmail.com wrote:
> On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> So you have written
>
> $pattern="^([a-z0-9.-_]{0,30})$"
>
> match a to z, 0 to 9, "." to '_' starting at the beginning of the line
> and ending at the end of the line with a maximum of 30 character and a
> minimum of 0 character.
>
> they are right about preg_match. which all it means is you need to
> wright you regex slightly differently and you can do fancy things if
> you wanted to.
>
> http://www.perl.com/doc/manual/html/pod/perlre.html
>
> so
>
> "/^[\w\.\-]{0,30}$/
> or
> "/^[a-zA-Z0-9\_\.\-]{0,30}$/
> which is the same thing just longer to write out
> and these are generally case sensitive remember so 'a' != 'A' (hence a-
> zA-Z and not just a-z)
>
>
> try that or at lest it should give you a good direction

You should not escape dots in character classes, as they are not meta
characters in that context. Also, if - (dash) is the last character in
the character class, it also does not need to be escaped. Using \w
would be better, as it would allow for more characters with regard to
locale.

[at] OP: PCRE regex are much more efficient than the POSIX flavor. If your
worries are over consistency, then stop using POSIX regex. :-) As
already mentioned here, even the PHP documentation team is
recommending PCRE preg_* functions over ereg_* functions at all turns.

Also, you already have a pattern, have you tried testing it? If you
have a specific problem, ask a specific question.

--
Curtis
Curtis [ Sa, 17 Februar 2007 07:09 ] [ ID #1632404 ]

Re: Newbie needs help with ereg regular expression

mvandenb [at] gmail.com wrote:
> On Feb 16, 6:55 am, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have to repost this to restate the question. No disrespect to the original
>> reply.
>>
>> Please can someone help regarding providing a regular expression for entering
>> a set of characters with letters, numbers, periods (.), hyphens (-), or
>> underscores (_) only.
>>
>> I need to do this using ereg
>>
>> I've got as far as this but it doesn't quite work:
>>
>> $pattern="^([a-z0-9.-_]{0,30})$";
>> if(ereg($pattern,$_SESSION['id']))
>> ...
>>
>> Thank you in advance.
>>
>> Kind regards,
>>
>> Raj (newbie)
>
> So you have written
>
> $pattern="^([a-z0-9.-_]{0,30})$"
>
> match a to z, 0 to 9, "." to '_' starting at the beginning of the line
> and ending at the end of the line with a maximum of 30 character and a
> minimum of 0 character.
>
> they are right about preg_match. which all it means is you need to
> wright you regex slightly differently and you can do fancy things if
> you wanted to.
>
> http://www.perl.com/doc/manual/html/pod/perlre.html
>
> so
>
> "/^[\w\.\-]{0,30}$/
> or
> "/^[a-zA-Z0-9\_\.\-]{0,30}$/
> which is the same thing just longer to write out
> and these are generally case sensitive remember so 'a' != 'A' (hence a-
> zA-Z and not just a-z)
>
>
> try that or at lest it should give you a good direction

You should not escape dots in character classes, as they are not meta
characters in that context. Also, if - (dash) is the last character in
the character class, it also does not need to be escaped. Using \w
would be better, as it would allow for more characters with regard to
locale.

[at] OP: PCRE regex are much more efficient than the POSIX flavor. If your
worries are over consistency, then stop using POSIX regex. :-) As
already mentioned here, even the PHP documentation team is
recommending PCRE preg_* functions over ereg_* functions at all turns.

Also, you already have a pattern, have you tried testing it? If you
have a specific problem, ask a specific question.

--
Curtis
Curtis [ Sa, 17 Februar 2007 07:09 ] [ ID #1632427 ]
PHP » alt.php » Newbie needs help with ereg regular expression

Vorheriges Thema: script error
Nächstes Thema: generating files for import into quicken