Regex - problem

Helloo…
how to make this below regular expression not to accept _ anywhere in
the string
/^[a-zA-Z0-9.]+[\w\s]*$/
how can i modify it…
Any Advices or Suggesions…
Thanks

The dot (after the 9) means any character; if you remove it, it’s
gonna only accept a-zA-Z0-9

Quoting Newb N. [email protected]:

Helloo…
how to make this below regular expression not to accept _ anywhere in
the string
/^[a-zA-Z0-9.]+[\w\s]*$/
how can i modify it…
Any Advices or Suggesions…
Thanks

if s =~ /_/
reject string
end

The dot is probably not the issue here as it appears as part of a
character sequence.

If you don’t want to match with any ‘’ then replace the \w since it
matches "alphanumeric + '
’".

It’s not clear to me what your intention is for the second set of square
braces, but it looks like you’re trying to get grouping. You probably
want parentheses instead.

Try something like this:

/^[0-9a-zA-Z.]+([0-9a-zA-Z]\s)*$/

-Donald

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs