From: computorist Date: 2008-06-19T02:23:48+09:00 Subject: Re: regex: splitting conditionally on | On Jun 18, 12:35 am, Sebastian Hungerecker wrote: > 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: sep...@jabber.org > ICQ: 205544826 This seems to work well. Searching for what I want is better than excluding the bits I don't want. Thanks