# Regular expression: zero-width look-behind?

**URL:** <https://rubytalk.org/t/regular-expression-zero-width-look-behind/6907>\
**Category:** ruby-talk\
**Created:** [17 July 2003 20:40 UTC](https://rubytalk.org/t/regular-expression-zero-width-look-behind/6907 "2003-07-17T20:40:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lei\_Wu](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@Lei\_Wu](https://rubytalk.org/u/Lei_Wu)\
**Post date:** [17 July 2003 20:40 UTC](https://rubytalk.org/t/regular-expression-zero-width-look-behind/6907/1 "2003-07-17T20:40:04Z")

</div>

Hi,

How do I use zero-width look-behind in regular expression? I tried  
f.sub!(/(?\<=\w)-/, ’ ')

But I got an error message:  
undefined (?..) sequence: /(?\<=\w)-/

Thanks in advance for any help.

Lei

---

<div class="post-metadata">

**Author:** ![Mark\_J\_Reed](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Mark\_J\_Reed](https://rubytalk.org/u/Mark_J_Reed)\
**Post date:** [17 July 2003 21:20 UTC](https://rubytalk.org/t/regular-expression-zero-width-look-behind/6907/2 "2003-07-17T21:20:19Z")

</div>

Apparently, you can’t. Looks like Ruby, at least as of 1.8pre2,  
doesn’t support lookbehind. Lookahead, yes; lookbehind, no.

-Mark

> **···**
>
> On Thu, Jul 17, 2003 at 01:26:27PM -0700, Lei Wu wrote:
> 
> > How do I use zero-width look-behind in regular expression? I tried  
> > f.sub!(/(?\<=\w)-/, ’ ')

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [18 July 2003 00:30 UTC](https://rubytalk.org/t/regular-expression-zero-width-look-behind/6907/3 "2003-07-18T00:30:57Z")

</div>

Hi,

> **···**
>
> At Fri, 18 Jul 2003 05:40:04 +0900, Lei Wu wrote:
> 
> > How do I use zero-width look-behind in regular expression? I tried  
> > f.sub!(/(?\<=\w)-/, ’ ')
> 
> You have to wait 1.9 or compile ruby with Oniguruma.
> 
> –  
> Nobu Nakada
