Rob Dixon schreef:

> I thought the group might like this one.
>
> I want a regex to check whether a string contains a sequence of
> non-space characters with /both/ word and non-word characters in it
> (\w and \W).
>
> So
>
>    'Rob'
>    'SHREWSBURY'
>    'SY3 8BH'
>    'Mike & Dave'
>
> all pass, but
>
>    'http://www.site.com/'
>    'Rob&Dave'
>    '2+2'
>
> all fail. I'll be thinking on this myself later...

- split on whitespace
- check each value with /\A(?:\w+|\W+)\z/

Combined:

  /\A\s*(?:\w+|\W+)(?:\s+(?:\w+|\W+))*\s*\z/

or if you normalize (1) the string first:

  /\A(?:\w+|\W+)(?: (?:\w+|\W+))*\z/


(1) normalize: s/\A\s+//, s/\s+\z//, s/\s+/ /g

-- 
Affijn, Ruud

"Gewoon is een tijger."



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to