Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: need regular expression to replace part of result based on a search pattern Date: Thu, 12 Jul 2012 11:24:21 -0400 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: <6aefda61-b66a-4e8f-8634-ef6a95f79c4d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 12 Jul 2012 15:24:25 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="d3779b2c4a3397eb5709eec94bad057a"; logging-data="11663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/t/UCIcyjHP1IA8zEz66+r" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Cancel-Lock: sha1:o+mfOLbHPK3SXUj34OVJ36Fr1LM= Xref: csiph.com comp.lang.java.programmer:15982 On 7/12/2012 10:28 AM, Jimmy wrote: > Thank you so much for everyone's response. > These CSV are inside a script and I've clean up the quotes. > > Want 1 line of regexp to change from column #6 (from top to bottom 'N','Y','N','Y','N','Y') > > 'blaha',NULL,'N','Y','N','N',NULL > 'blahb',NULL,'Y','Y','Y','N',NULL > 'blahc',NULL,'N','N','N','N',NULL > 'blahd',NULL,'N','N','Y','N',NULL > 'blahe',NULL,'N','N','N','N',NULL > > To following result in column #6 (from top to bottom 'Y','Y','Y','Y','Y','Y') > > 'blaha',NULL,'N','Y','Y','N',NULL > 'blahb',NULL,'Y','Y','Y','N',NULL > 'blahc',NULL,'N','N','Y','N',NULL > 'blahd',NULL,'N','N','Y','N',NULL > 'blahe',NULL,'N','N','Y','N',NULL > > Can someone please help? If you are certain that commas appear *only* as field separators and never inside quoted material, you can use something like (untested) "(.*?,){5}.*?,(.*)" After matching you'd then paste group(1) + "'Y'," + group(2). If quoted material can contain commas that don't count as field separators, I don't think regular expressions can do the job at all. You'll need to parse the strings in a context-sensitive way. "Some people, when confronted with a problem, think `I know, I'll use regular expressions.' Now they have two problems." -- Jamie Zawinski -- Eric Sosman esosman@ieee-dot-org.invalid