Results 1 to 5 of 5
  1. #1
    Death Sickle is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Regular Expressions Help

    Hi, i'm trying to construct a java program to measure the cyclomatic complexity of other java programs

    the trouble i'm having is with regular expressions

    Example :
    I'm trying to create a general construct to identify if statements.

    Java Code:
    if(file_line.matches
    ("if \\( [a-z]*\\d*] [==|<=|>=|!|\\)]")
    First of all, i would like to know if this expression is valid.

    [[a-z]*\\d*]
    checks for any possible variable name..

    I intend [==|<=|>=|!|\\)] to check for the various conditions that may be present. However, i read that the [ ] grouping is used for literals.

    Could anyone direct me towards how to proceed with this task
    Last edited by Death Sickle; 04-04-2011 at 04:22 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Quote Originally Posted by Death Sickle View Post
    First of all, i would like to know if this expression is valid.

    [a-z]*\\d*]
    You tell us. One opening bracket, 2 closing brackets.

  3. #3
    Death Sickle is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    my bad..edited it..that was my fault in the forum post. got confused with the [] from QUOTE

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Ahh, ok.

    Another problem, you will need to escape your round brackets.

  5. #5
    Death Sickle is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Regular Expressions problem
    By mohammedelbes in forum Advanced Java
    Replies: 7
    Last Post: 01-05-2011, 12:12 PM
  2. regular expressions
    By sozeee in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 10:58 PM
  3. Using regular expressions for search
    By carderne in forum New To Java
    Replies: 9
    Last Post: 05-24-2009, 04:58 AM
  4. Regular Expressions in java
    By blue404 in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2008, 03:43 AM
  5. Using Quantifiers in regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 11:43 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
  •