[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regex: \ not in gsub?

Shea Martin

1/15/2007 7:55:00 PM

I often use \< and \> to denote the start and end of word. But they
don't seem to work with gsub. Am I missing something?

I would expect the following:
"xword1 word2 tword3".gsub( /\<word, 'XXXX' )

to return "xword1 XXXX2 tword3", but instead it the string unchanged.

If the \< and \> are not supported, is there an alternative that ruby
provides? Thanks.

Thanks,

~S
1 Answer

Rodrigo Bermejo

1/15/2007 8:16:00 PM

0

Shea Martin wrote:
> I often use \< and \> to denote the start and end of word. But they
> don't seem to work with gsub. Am I missing something?
>
> I would expect the following:
> "xword1 word2 tword3".gsub( /\<word, 'XXXX' )
>
> to return "xword1 XXXX2 tword3", but instead it the string unchanged.
>
> If the \< and \> are not supported, is there an alternative that ruby
> provides? Thanks.
>
> Thanks,
>
> ~S

"xword1 word2 tword3".gsub( /\bword/, 'XXXX' )

$rm rm

--
Posted via http://www.ruby-....