From: Sebastian Hungerecker Date: 2008-06-18T16:35:07+09:00 Subject: Re: regex: splitting conditionally on | computorist wrote: > I'm parsing mediawiki markup and I'd like to split a multi-line string > on | (vertical-bar), but only if it isn't contained w/in another > pattern. > > | name1 = value1 > | name2 = value2 | name3 = value3 > | name4 = [[foo|bar]] > > I'd like String.split(/pattern/) to return ['name1 = value1','name2 = > value2','name3 = value3','name4 = [[foo|bar]]'] > > I've working on a negative look-ahead pattern without success and my > brain is tired. > > Thanks for any suggestions str.split /\s*\|\s*(?=\s*\w+\s*=)/ I don't know whether this exactly meets your requirement, but this will split only on |s that are followed by a word and a =. For your sample input that gives the desired result. HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826