# Re: Pattern based substitution

**URL:** <https://www.ruby-forum.com/t/re-pattern-based-substitution/72364>\
**Category:** Ruby\
**Created:** [October 16, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/re-pattern-based-substitution/72364 "2006-10-16T19:29:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/re-pattern-based-substitution/72364/1 "2006-10-16T19:29:24Z")

</div>

From: Daniel Mircea

> How does pattern based substitution works ?

See  
[http://phrogz.net/ProgrammingRuby/tut\_stdtypes.html#regularexpressions](http://phrogz.net/ProgrammingRuby/tut_stdtypes.html#regularexpressions)  
particularly the section near the end of that page titled “Pattern-Based  
Substitution”.

> For example, how does textilize replace all occurrences of  
> _hello world_  
> with **hello world**?

Here’s a simple example (probably not what Textilize uses):  
source.gsub( /\*([^\*]+)\*/, ‘ **\1** ’ )
