From: Benoit Cerrina Date: 2001-11-30T07:15:25+09:00 Subject: [ruby-talk:26974] Re: How to match '|' but not '\|' "Ross Shaw" wrote in message news:qJxN7.386812$bY5.1671783@news-server.bigpond.net.au... > 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 I'm not sure what the syntax actual = 'Split|me|up\|into|four' (/??????/) is supposed to be but my best guess has been actual = 'Split|me|up\|into|four'.scan(/[^|\\]*(?:\\\|[^|\\]*)*/) Benoit actual.scan(/[^|\\]*(?:\\\|[^|\\]*)*/)