From: Michael Neumann Date: 2001-11-30T07:46:25+09:00 Subject: [ruby-talk:26987] Re: How to match '|' but not '\|' Ross Shaw wrote: > I'm a bit of a nuby to regular expressions so I need a little assistance. > > I have a string that I want to split into separate words that are separated > by the pipe character '|'. However I do NOT want to split at points where > the pipe is preceded by a backslash '\|'. > > Here's a quick unit test. Can you fill in the missing regexp? > > def test_string_split > actual = 'Split|me|up\|into|four' (/??????/) > expected = %w[Split me up\into four] > assert_equals(expected, actual) > end Try this: actual.scan(/((\\.|[^|])+)/).map{|t| t[0]} Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de