Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11085

Re: Regex doesn't recognize single quote

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe10.iad.POSTED!83aa503d!not-for-mail
From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: Regex doesn't recognize single quote
References <74f4b448-24bf-448f-9f4a-06fd1b79c86d@o12g2000vbd.googlegroups.com>
In-Reply-To <74f4b448-24bf-448f-9f4a-06fd1b79c86d@o12g2000vbd.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Lines 24
Message-ID <ZLLNq.55350$mJ.21710@newsfe10.iad> (permalink)
X-Complaints-To abuse@newsrazor.net
NNTP-Posting-Date Fri, 06 Jan 2012 23:49:13 UTC
Date Fri, 06 Jan 2012 15:49:12 -0800
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11085

Show key headers only | View raw


On 1/6/12 2:08 PM, 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']+", "");
>
> Thanks a lot,
It works for me, which indicates the problem is somewhere in the code 
you didn't post.  Here is an SSCCE:

public class Works {
     public static void main(String[] args) {
         String val = "ab'de+fg";
         System.out.println(val.replaceAll("[^\\w']+", ""));

     }
}

Try posting exactly the code which causes the problem.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Regex doesn't recognize single quote Jerric <jerricgao@gmail.com> - 2012-01-06 14:08 -0800
  Re: Regex doesn't recognize single quote Martin Gregorie <martin@address-in-sig.invalid> - 2012-01-06 22:23 +0000
  Re: Regex doesn't recognize single quote Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-01-06 23:48 +0100
  Re: Regex doesn't recognize single quote Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-06 15:49 -0800
    Re: Regex doesn't recognize single quote Jim Janney <jjanney@shell.xmission.com> - 2012-01-07 19:02 -0700
      Re: Regex doesn't recognize single quote Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-09 09:58 -0800
  Re: Regex doesn't recognize single quote Roedy Green <see_website@mindprod.com.invalid> - 2012-01-06 21:47 -0800
    Re: Regex doesn't recognize single quote Roedy Green <see_website@mindprod.com.invalid> - 2012-01-07 14:41 -0800
      Re: Regex doesn't recognize single quote Rafael Villar <morgano5@hotmail.com> - 2012-01-08 09:05 +1000
        Re: Regex doesn't recognize single quote Rafael Villar <morgano5@hotmail.com> - 2012-01-08 09:10 +1000
        Re: Regex doesn't recognize single quote Lew <noone@lewscanon.com> - 2012-01-07 17:20 -0800
      Re: Regex doesn't recognize single quote Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-09 10:08 -0800
        Re: Regex doesn't recognize single quote Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-09 10:33 -0800
    Re: Regex doesn't recognize single quote Roedy Green <see_website@mindprod.com.invalid> - 2012-01-07 14:48 -0800
      Re: Regex doesn't recognize single quote Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-07 20:58 -0400

csiph-web