# Regex - problem

**URL:** <https://www.ruby-forum.com/t/regex-problem/174128>\
**Category:** Rails\
**Created:** [August 21, 2009, 4:58am UTC](https://www.ruby-forum.com/t/regex-problem/174128 "2009-08-21T04:58:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 21, 2009, 4:58am UTC](https://www.ruby-forum.com/t/regex-problem/174128/1 "2009-08-21T04:58:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 21, 2009, 6:42am UTC](https://www.ruby-forum.com/t/regex-problem/174128/2 "2009-08-21T06:42:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 21, 2009, 7:08am UTC](https://www.ruby-forum.com/t/regex-problem/174128/3 "2009-08-21T07:08:37Z")

</div>

Quoting Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 22, 2009, 8:03am UTC](https://www.ruby-forum.com/t/regex-problem/174128/4 "2009-08-22T08:03:08Z")

</div>

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
