Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    simple match question

    I want to filter scalars to be numbers, letters, -, and maybe a space if they dont hyphenate their last name ( part of which to be anything else). like:
    Code:
    ($text !~ /^[w -}/) or is it like $text =~ s/{A-Za-z0-9}*/ /g ?
    How close am I?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by dkenney1 View Post
    I want to filter scalars to be numbers, letters, -, and maybe a space if they dont hyphenate their last name ( part of which to be anything else). like:
    Code:
    ($text !~ /^[w -}/) or is it like $text =~ s/{A-Za-z0-9}*/ /g ?
    Code:
    $text !~ /[^\w\s-]+/;
    second is a substitute, not a match, and will remove any char if is in A-Z, a-z or 0-9, that if you replace { and } with [ and ],

    best regards
    Last edited by oesxyl; 12-30-2009 at 01:10 AM.

  • Users who have thanked oesxyl for this post:

    dkenney1 (12-30-2009)

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    I would try:

    Code:
    unless ( $variable =~ /^[-a-zA-Z0-9 ]+$/ ) {
      exit;
    }
    or, to allow underscores as well...

    Code:
    $variable =~ /^(-\w\ )+$/
    not tested

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • Users who have thanked bazz for this post:

    dkenney1 (12-30-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •