Results 1 to 4 of 4
  1. #1
    mohammedelbes is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Regular Expressions for certain format

    Hi guys,

    Im new to writing and learning Regular expressions. I'm trying to write a regular expression for a string of ANY size and can have only numbers[0-9] OR Commas "," OR the letter "S". Itried this one Im not sure why its not working

    Pattern datePattern = Pattern.compile("[\\d+|,|[S]]{?}");
    is the above REGEX correct for my description?

    Thank you all

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    No,

    Java Code:
    [\\d,S]+
    anything in the character class of a digit, comma, S. and one or more of these
    alternatively, we could write
    Java Code:
    [0-9,S]+

  3. #3
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by mohammedelbes View Post
    Hi guys,

    Im new to writing and learning Regular expressions. I'm trying to write a regular expression for a string of ANY size and can have only numbers[0-9] OR Commas "," OR the letter "S". Itried this one Im not sure why its not working

    Pattern datePattern = Pattern.compile("[\\d+|,|[S]]{?}");
    is the above REGEX correct for my description?

    Thank you all
    if you can only have [0-9], a comma or S, then this is the pattern you need
    Java Code:
    "^[0-9,S]+$"
    This match from beginning to end of the string.

  4. #4
    mohammedelbes is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. regular expressions
    By sozeee in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:58 PM
  2. Replies: 23
    Last Post: 04-18-2010, 09:35 PM
  3. Regular Expressions in java
    By blue404 in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2008, 03:43 AM
  4. Using Quantifiers in regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 10:43 AM
  5. Regular expressions quantifiers
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:18 AM

Posting Permissions

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