For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2004 > Regex for "not any words(lines) preceeded by spaces"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Regex for "not any words(lines) preceeded by spaces"
Edward Wijaya

2004-05-18, 6:31 am

Hi,

[^\s.] or [^\s[a-zA-z]] doesn't seem to work.
Anything wrong with my regex?

Thanks.

Regards
Edward WIJAYA
SINGAPORE


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Mark Clements

2004-05-18, 6:31 am

Edward Wijaya wrote:
> Hi,
>
> [^\s.] or [^\s[a-zA-z]] doesn't seem to work.
> Anything wrong with my regex?

[^\s.] will match non-whitespace or non-anything (^ inside a character
class negates the class). I'll assume that you are trying to anchor to
start-of line, though your spec doesn't mention it. You spec refers to
spaces and not whitespace, though this time I'll assume you mean spaces.

How about :
^ +\W+

though without any test data or expected results it's difficult to see
exactly what you're after.

Mark
Gunnar Hjalmarsson

2004-05-18, 7:31 am

Mark Clements wrote:
> [^\s.] will match non-whitespace or non-anything


No. A dot is not special within brackets. It matches any
non-whitespace character except a dot.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Mark Clements

2004-05-18, 7:31 am

Xref: number1.nntp.dca.giganews.com comp.lang.perl.misc:540675

Gunnar Hjalmarsson wrote:
> Mark Clements wrote:
>
>
>
> No. A dot is not special within brackets. It matches any non-whitespace
> character except a dot.
>

er - yeah. schoolboy error :)
Anno Siegel

2004-05-18, 8:38 am

Edward Wijaya <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
> Hi,
>
> [^\s.] or [^\s[a-zA-z]] doesn't seem to work.
> Anything wrong with my regex?


Hard to say before *you* say what exactly you expect it to do. The
statement in your subject is ambiguous (and you should have re-stated
it in the body of your text).

Meanwhile it would be a good idea to acquaint yourself with the
function of character classes "[...]" in regular expressions.
Those you are using above don't make much sense. In particular
you don't seem to understand that a character class matches a
single character, not many. Also, "^" has a different meaning
in character classes (negation) and outside (anchor to the beginning
the string).

Anno
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com