From: ben on
Just wondering if a literal . needs to be escaped inside a bracket
expression within a regexp. For example, I want this fragment to match
any sequence of alphanumeric characters, underscores or '.'s

[[:alnum:]_.]

The man page for re_syntax suggests that only ] and - need to be
escaped inside bracket expression, but it's not 100% clear on that
point.
From: Alexandre Ferrieux on
On Apr 5, 11:18 am, "b...(a)spam.com" <ben.carb...(a)gmail.com> wrote:
> Just wondering if a literal . needs to be escaped inside a bracket
> expression within a regexp. For example, I want this fragment to match
> any sequence of alphanumeric characters, underscores or '.'s
>
> [[:alnum:]_.]
>
> The man page for re_syntax suggests that only ] and - need to be
> escaped inside bracket expression, but it's not 100% clear on that
> point.

What may be misleading you is the use of the dot in [. .] (collating
elements). But note that these are distinguishable from [.] or even
[ANYTHING.] or [.ANYTHING]. So no, a single dot doesn't need escaping
in a bracket expression. Personally I even tend to write [.] instead
of \. because backslashes sting my eyes ;-)

-Alex
From: ben on
Thanks muchly.
From: Glenn Jackman on
At 2010-04-05 05:46AM, "Alexandre Ferrieux" wrote:
> On Apr 5, 11:18�am, "b...(a)spam.com" <ben.carb...(a)gmail.com> wrote:
> > Just wondering if a literal . needs to be escaped inside a bracket
> > expression within a regexp. For example, I want this fragment to match
> > any sequence of alphanumeric characters, underscores or '.'s
> >
> > [[:alnum:]_.]
> >
> > The man page for re_syntax suggests that only ] and - need to be
> > escaped inside bracket expression, but it's not 100% clear on that
> > point.
>
> What may be misleading you is the use of the dot in [. .] (collating
> elements). But note that these are distinguishable from [.] or even
> [ANYTHING.] or [.ANYTHING]. So no, a single dot doesn't need escaping
> in a bracket expression. Personally I even tend to write [.] instead
> of \. because backslashes sting my eyes ;-)

Additionally, you an write your character class as: [\w.]
since a word char (\w) is letters, numbers and underscore

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
From: Donal K. Fellows on
On 5 Apr, 20:02, Glenn Jackman <gle...(a)ncf.ca> wrote:
> Additionally, you an write your character class as:  [\w.]
> since a word char (\w) is letters, numbers and underscore

Only for some classes (the "positive" ones). Check the docs for
re_syntax to see which is which.

Donal.