Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: Regex in Java for string with apostrophes.

  1. #1
    that_me123 is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default Regex in Java for string with apostrophes.

    I need to match a pattern to strip the 's as well as the ending ' from words. I've used the regex pattern (\\w+)('s$|s'$|'$). I need the first group. However what is happening with this pattern is a word like cats' matches with the third pattern i.e '$. Hence my group(1) still has cats. I tried using the pattern (\\w+)('s$|s'$|([^s] & '$).But here what happens is for a word abc' group 1 has just ab and group 2 has c'. Any suggestions on how to handle this.

    I need to match a pattern to strip the 's as well as the ending ' from words. I've used the regex pattern (\\w+)('s$|s'$|'$). I need the first group. However what is happening with this pattern is a word like cats' matches with the third pattern i.e '$. Hence my group(1) still has cats. I tried using the pattern (\\w+)('s$|s'$|([^s] & '$).But here what happens is for a word abc' group 1 has just ab and group 2 has c'. Any suggestions on how to handle this.
    Last edited by Norm; 09-28-2013 at 12:49 AM. Reason: Duplicate post

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Regex in Java for string with apostrophes.

    I don't understand this very well, but I think it's the right tool for the job: Quantifiers (The Java™ Tutorials > Essential Classes > Regular Expressions)
    Get in the habit of using standard Java naming conventions!

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,648
    Rep Power
    5

    Default Re: Regex in Java for string with apostrophes.

    What might help is if you give several examples of before and after.

    Regards,
    Jim
    DarrylBurke likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. split string with regex
    By chkontog in forum New To Java
    Replies: 1
    Last Post: 07-27-2013, 01:40 PM
  2. Find character at the end of the string with regex
    By samnjugu in forum New To Java
    Replies: 4
    Last Post: 10-04-2011, 10:47 AM
  3. String operations or regex please
    By africanhacker in forum New To Java
    Replies: 7
    Last Post: 03-31-2011, 07:14 PM
  4. breaking up a string, a regex problem!!
    By A.n.H in forum Advanced Java
    Replies: 7
    Last Post: 05-18-2010, 02:39 AM
  5. breaking up a string, a regex problem!!
    By A.n.H in forum Advanced Java
    Replies: 0
    Last Post: 05-17-2010, 03:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •