Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Regex doesn't recognize single quote Date: Fri, 6 Jan 2012 22:23:41 +0000 (UTC) Organization: UK Free Software Network Lines: 19 Message-ID: References: <74f4b448-24bf-448f-9f4a-06fd1b79c86d@o12g2000vbd.googlegroups.com> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1325888621 7186 84.45.235.129 (6 Jan 2012 22:23:41 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Fri, 6 Jan 2012 22:23:41 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11082 On Fri, 06 Jan 2012 14:08:49 -0800, Jerric wrote: > Hi, I need to remove special characters, except \w and single quotes, > from a string, can someone please help me on the regex? > > for example, I have "ab'de+fg", I want to get "ab'defg", and I tried the > following code, but it removed single quote. seems to me java cannot > handle the pattern like [^']. > > String val = "ab'de+fg"; > val = val.replaceAll("[^\\w']+", ""); > Did you try escaping the single quote? -- martin@ | Martin Gregorie gregorie. | Essex, UK org |