From: Logan Capaldo Date: 2005-02-18T10:15:08+09:00 Subject: Re: Newbie needs help with escaping regex On Fri, 18 Feb 2005 10:06:04 +0900, Zach Dennis wrote: > Paul Wistrand wrote: > > Hi, > > I have a simple project that I thought I'd have a crack at in Ruby. I > > want to retrieve a list of names from a web page but the Ruby interpreter is > > giving me allot of trouble in parsing the pattern for the regular > > expression. The pattern I wanted to use was the following : > > > > pattern = > > / > ([^&]*)&PlayerName=([^"]*)">((\n|.)*?)/ > > > > understandably the forward slash in the closing span tag causes Ruby to > > think this is the end of the pattern. Hence my question is how the heck do I > > escape this? > > > > Thanks > > Paul > > > > B.T.W I realise that following works just as well... > > pattern = > > / > ([^&]*)&PlayerName=([^"]*)">((\n|.)*?) > Just add a \ slash before all characters you want to escape, in this > case the forward slashes. > > example: > rgx = /<\/span>/ > > HTH, > > Zach > > An alternative is to use %r{} syntax. %r{(now|I)can (use)+ as many /* as I? want} Of course the downside being is now you have to escape { }. But your pattern doesn't seem to contain any of those anyway.