The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024

Latest message you have seen: Re: Telephone Systems


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: OT: Quickie RegEx question for gurus.



Tony,

You are pretty close:

m/^.{3,}$/s

would find you all strings containing three or more characters however it
would also match "a\nb" as the /s informs the regex engine to
treat a
multiline string as a single string hence it effectively translates a
newline into a space which matches.  so even better would be:

m/^\w{3,}$/s

which will only match alphanumeric strings of three or more characters.
hence:

$ cat /tmp/foo
foreach ( @ARGV ) {
if (m/^\w{3,}/s) { print "$_ - matched...\n"; }
}
$ perl /tmp/foo "abc" "a\nb" "abcd"
"ab\nc" "123"
abc - matched...
abcd - matched...
123 - matched...

thanks
kieran


-----Original Message-----
From: lists@xxxxxxx [mailto:lists@xxxxxxx]
Subject: [ukha_d] OT: Quickie RegEx question for gurus.

Soz, but this is killing me - it should be soooooo simple but it ain't :(

I need to validate that a string is at least 3 characters long.
fine, I use an expression of:
/^.{3,}$/

Works fine....except if there is a new line in the string being searched -
then
I just get nothing :(
I tried:
/^.{3,}\s*\S*$. which, would appear to say "Match at least three
characters
(not \n though) then 0 or more white space followed by 0 or more non white
space.
Still don't work :(

any thoughts peeps?

thanks,

Tony

UK Home Automation Meet 2004 - BOOK NOW!
http://www.ukha2004.com

http://www.automatedhome.co.uk
Post message: ukha_d@xxxxxxx
Subscribe:  ukha_d-subscribe@xxxxxxx
Unsubscribe:  ukha_d-unsubscribe@xxxxxxx
List owner:  ukha_d-owner@xxxxxxx


Home | Main Index | Thread Index

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.