Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Question What Regex matches this String?

    How to get the regular expression for this String :

    $OK:COMMAND=4,45,,internet,,,60.210.45.68,1050,30, 168.95.1.1

    I have tried this one but it seems that it doesn't work :

    public static final String commandMotif = "^\\$OK:COMMAND=(\\w){0,1},(\\w){0,1},(\\w){0,1},( \\w){0,1},(\\w){0,1},(\\w){0,1},(\\w){0,1},(\\w){0 ,1},(\\w){0,1},(\\w){0,1}";

    NB : I can have some data between two comma and it can be empty sometimes also.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: What Regex matches this String?

    I assume that the number of elements (values between commas) in this String is always the same, so split the string on commas and don't bother with a regex.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: What Regex matches this String?

    By definition the String itself matches itself (and infinitely many more match as well).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: What Regex matches this String?

    This solution works now :

    public static final String commandMotif = "^\\$OK:COMMAND=([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*),([\\w.]*)";

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. Regex: find all possible matches
    By Alessio in forum New To Java
    Replies: 3
    Last Post: 10-19-2010, 01:10 PM
  3. Replies: 0
    Last Post: 11-17-2009, 01:58 PM
  4. How "Pattern.matches(regex, input)" function works?
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 04-26-2009, 12:46 AM
  5. Regex that matches whole word
    By moaxjlou in forum New To Java
    Replies: 13
    Last Post: 11-04-2008, 05:48 PM

Posting Permissions

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