# Regexp differences between Ruby and ROR \[hpricot\]

**URL:** <https://www.ruby-forum.com/t/regexp-differences-between-ruby-and-ror-hpricot/111295>\
**Category:** Rails\
**Created:** [August 5, 2007, 6:45am UTC](https://www.ruby-forum.com/t/regexp-differences-between-ruby-and-ror-hpricot/111295 "2007-08-05T06:45:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chet\_sanders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@chet\_sanders](https://www.ruby-forum.com/u/chet_sanders)\
**Post date:** [August 5, 2007, 6:45am UTC](https://www.ruby-forum.com/t/regexp-differences-between-ruby-and-ror-hpricot/111295/1 "2007-08-05T06:45:57Z")

</div>

I am trying to get hpricot to work from within rails and ran into this  
peculiarity. I had a situation where the script runs fine if run as a  
ruby script but bombs if called from within rails (as a method of a  
model). After some debugging, it came down to this …

Fire up script\console from the root directory of a rails project -

Loading development environment.

> > expr = “title”  
> > =\> “title”
> 
> > m = expr.match(/(^[#.]?)([a-z0-9]\*)/)  
> > =\> #MatchData:0xb78d1370
> 
> > $’  
> > =\> nil
> 
> > m.post\_match  
> > =\> “”

$’ and m.post\_match are different.

Do the same in irb -  
irb(main):001:0\> expr = “title”  
=\> “title”  
irb(main):002:0\> m = expr.match(/(^[#.]?)([a-z0-9]\*)/)  
=\> #MatchData:0xb7c07b48  
irb(main):003:0\> $’  
=\> “”  
irb(main):004:0\> m.post\_match  
=\> “”

$’ and m.post\_match are the same.

Ironically if you test this on windows results are script\console are  
identical to those of irb. But for Mac or Ubuntu I see the above  
behavior.  
Tested with ruby 1.8.4.

questions -

1. Is this expected behavior?
2. Can you suggest a workaround ? I would prefer not to touch the gem  
code in hpricot – unless it is the only alternative.

- Chet

---

<div class="post-metadata">

**Author:** ![chet\_sanders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@chet\_sanders](https://www.ruby-forum.com/u/chet_sanders)\
**Post date:** [August 8, 2007, 4:41am UTC](https://www.ruby-forum.com/t/regexp-differences-between-ruby-and-ror-hpricot/111295/2 "2007-08-08T04:41:36Z")

</div>

Any body run into this?
