tags:

views:

56

answers:

3

I have a string h2#test- ruby is so awesome, blah, blah, blah. I want to have #test to be the only characters left. is there a way in ruby to run a Regular Expression that removes all other characters?

+1  A: 
str.match(/(\#\w+)/)[1]
Tass
Thanks, worked great!
errorhandler
A: 

Don't think of it as removing all other characters...think of it as capturing what you want.

'h2#test- ruby is so awesome, blah, blah, blah' =~ /(#test)/
your_captured_text = $1
Doug R
A: 
str[/#[a-z]+/i]
Nakilon