Re: Search string for occurneces of words stored in array
- From: Jens Wille <jens.wille@xxxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:34:22 -0500
David A. Black [2008-04-30 16:29]:
ha, didn't know that ;-) thank you!Jens Wille [2008-04-30 16:18]:It actually does it for you:
sentence =~ Regexp.union(*words)one addition regarding the regexp, though. in case words may
contain special characters, it's safer to escape them first:
sentence =~ Regexp.union(*words.map { |word| Regexp.escape(word) })
Regexp.union("a",".b") => /a|\.b/
.
- References:
- Search string for occurneces of words stored in array
- From: John Butler
- Re: Search string for occurneces of words stored in array
- From: Phillip Gawlowski
- Re: Search string for occurneces of words stored in array
- From: Jens Wille
- Re: Search string for occurneces of words stored in array
- From: Jens Wille
- Re: Search string for occurneces of words stored in array
- From: David A. Black
- Search string for occurneces of words stored in array
- Prev by Date: Re: Dynamic class instantiation by iteration
- Next by Date: Re: How to create "def method(item)= (value)" ?
- Previous by thread: Re: Search string for occurneces of words stored in array
- Next by thread: Re: Search string for occurneces of words stored in array
- Index(es):
Relevant Pages
|