# Regular expression to identity special character

**URL:** <https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654>\
**Category:** Rails\
**Created:** [September 27, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654 "2008-09-27T13:37:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 27, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/1 "2008-09-27T13:37:02Z")

</div>

Hello friends i need a regular expression which will check if the string  
contain the special character or not? and accordingly it should return  
true,  
false value.

Thanks  
abhi

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 27, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/2 "2008-09-27T13:47:34Z")

</div>

Hey Fred,  
Suppose i have a string “abcde fghi” it should gives true, and suppose  
if i  
have a string “abcd %$# fghi” it should return false.

Thanks

On Sat, Sep 27, 2008 at 5:13 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 27, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/3 "2008-09-27T13:44:39Z")

</div>

On Sep 27, 12:36 pm, “Abhishek shukla” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello friends i need a regular expression which will check if the string  
> contain the special character or not? and accordingly it should return true,  
> false value.

Depends entirely on what you mean by special character?

Fred

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 27, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/4 "2008-09-27T14:42:34Z")

</div>

That’s still not very precise. Do you mean anything that’s not a  
letter or a space? What about punctuation, numbers etc… ? You’re  
probably just going to end up with one of the builtin character  
classes like \w or custom ones like [a-z]

Sent from my iPhone

On 27 Sep 2008, at 12:47, “Abhishek shukla” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 27, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/5 "2008-09-27T16:05:44Z")

</div>

yes basically i don’t want my string should contain any ‘punctuation’ if  
so  
then it should return false.  
regards  
abhishek

On Sat, Sep 27, 2008 at 6:11 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 28, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/6 "2008-09-28T15:11:27Z")

</div>

Hi Abhishek,

Take a look on this article:

> **[Bitwising Ruby](http://marcricblog.blogspot.com/2008/08/bitwising-ruby.html)**
>
> This week some students come up with solutions using or appropriate to use bitwise operations, so, it is time to refresh the memory about th...

More specifically, the last example.

On that case I just consider words. You will need to adapt it to your  
needs.

Regards.

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [September 28, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/regular-expression-to-identity-special-character/149654/7 "2008-09-28T19:59:04Z")

</div>

You can use [http://www.rubular.com/](http://www.rubular.com/) to test and find the regex you  
need.
