# Help with regexp's

**URL:** <https://www.ruby-forum.com/t/help-with-regexps/196387>\
**Category:** Ruby\
**Created:** [October 12, 2010, 3:11pm UTC](https://www.ruby-forum.com/t/help-with-regexps/196387 "2010-10-12T15:11:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bcef8e/32.png) [@Thiago\_M](https://www.ruby-forum.com/u/Thiago_M)\
**Post date:** [October 12, 2010, 3:11pm UTC](https://www.ruby-forum.com/t/help-with-regexps/196387/1 "2010-10-12T15:11:59Z")

</div>

Is there any way to a regexp allow any character but the comma?

My regexp is getting ugly like  
/(\x2E|\x3A|\x27|\x28|\x29|\x2D|\x21|\x2B)\*/  
and so on(i ommited the real one for the love of god)

I’m even thinking about implementing it myself like

if not comma  
pass  
else  
not\_pass  
end

isn’t there a way to extend the way ruby deals with regexp and make  
something like “/everythingbutnotcomma” mean what i want?

I’m sorry of my lack of knowledge about regexps… I’m trying to really  
learn it once and for all.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Thiago\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bcef8e/32.png) [@Thiago\_M](https://www.ruby-forum.com/u/Thiago_M)\
**Post date:** [October 12, 2010, 3:17pm UTC](https://www.ruby-forum.com/t/help-with-regexps/196387/2 "2010-10-12T15:17:38Z")

</div>

On Tue, Oct 12, 2010 at 3:11 PM, Thiago M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is there any way to a regexp allow any character but the comma?

Use a negated character class [^,] or use negated matching !~.

> isn’t there a way to extend the way ruby deals with regexp and make  
> something like “/everythingbutnotcomma” mean what i want?

What exactly are you trying to achieve with matching? Do you want to  
make sure there is no comma in a sequence or do you want to do  
substitutions?

> I’m sorry of my lack of knowledge about regexps… I’m trying to really  
> learn it once and for all.

I highly recommend “Mastering Regular Expressions”.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Thiago\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bcef8e/32.png) [@Thiago\_M](https://www.ruby-forum.com/u/Thiago_M)\
**Post date:** [October 12, 2010, 3:26pm UTC](https://www.ruby-forum.com/t/help-with-regexps/196387/3 "2010-10-12T15:26:23Z")

</div>

On Tue, Oct 12, 2010 at 8:11 AM, Thiago M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## not\_pass
> 
> Thiago Fernandes Massa  
> 11 83979414

Use a negated character class /[^,]/

Here is an example [Rubular: [^,]](http://www.rubular.com/r/6zUr2HVznL)

Everything that matches the regexp gets highlighted. In this case, every  
char matches, so it gets highlighted. Except the comma, because it does  
not  
match since the caret in the front of the character class says “match  
anything except” Here is more on character classes, if you are  
interested

> **[Regexp Tutorial - Character Classes or Character Sets](https://www.regular-expressions.info/charclass.html)**
>
> In a regular expression, square brackets are used to indicate character classes, which matches any of the characters in the character set.
