# Regex: \\\<start-of-word, and end-of-word\\\> not in gsub?

**URL:** <https://www.ruby-forum.com/t/regex-start-of-word-and-end-of-word-not-in-gsub/81864>\
**Category:** Ruby\
**Created:** [January 15, 2007, 9:00pm UTC](https://www.ruby-forum.com/t/regex-start-of-word-and-end-of-word-not-in-gsub/81864 "2007-01-15T21:00:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [January 15, 2007, 9:00pm UTC](https://www.ruby-forum.com/t/regex-start-of-word-and-end-of-word-not-in-gsub/81864/1 "2007-01-15T21:00:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [January 15, 2007, 9:15pm UTC](https://www.ruby-forum.com/t/regex-start-of-word-and-end-of-word-not-in-gsub/81864/2 "2007-01-15T21:15:29Z")

</div>

Shea M. 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
