Results 1 to 3 of 3
  1. #1
    pavan528 is offline Member
    Join Date
    Sep 2012
    Posts
    13
    Rep Power
    0

    Default Regular Expressions for Range Statements

    Hi all,
    I have the following Output
    _G7120+1#=K,
    _G7132+_G7133#=_G7120,
    _G7144+_G7145#=_G7132,
    _G7156+_G7157#=_G7144,
    _G7168*Z#=_G7156,
    _G7180*Z#=_G7168,
    _G7192*Z#=_G7180,
    _G7204*Y#=_G7192,
    _G7192, in 10..15 \/ 16
    X*Y#=_G7204,
    X+Y#=_G7133,
    _G7145+X#=Z1_a,
    Y in 1..15,
    Z/Y#=_G7157,
    __X in 1..15 \/ 17 \/ 20.

    From this, I need to extract the statements of variables that do not start with _G . I mean, I need to extract, Y in 1..15 , __X in 1..15 \/17\/20 but not _G7145 in 10..15 \/ 16.

    I am using regular Expression for this as [^_G]^[A-Za-z0-9_]+ in|ins [-9 -9]..[-9-9] [\/[-9-9]..[-9-9]]+

    Can someone kindly confirm if it is right or if not correct it?

    Thanks,

  2. #2
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Regular Expressions for Range Statements

    I'm wondering what's stopping you from using just String.contains(s) and String.startsWith(prefix)? E.g., if line refers to a line of text,
    Java Code:
    if (line.contains(" in ") && !line.startsWith("_G"))
    should match only Y in 1..15 and __X in 1..15 \/17\/20

    Keep it simple, I'm thinking...

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

    Default Re: Regular Expressions for Range Statements

    Anytime there is an underscore in the last statement of your code snippet it won't show up. So place an empty comment after it (e.g. //). It's
    another problem with the formatter.

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

Similar Threads

  1. Regular expressions
    By freelancer in forum New To Java
    Replies: 1
    Last Post: 11-25-2011, 12:41 PM
  2. Regular Expressions Help
    By Death Sickle in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 04:21 AM
  3. Regular Expressions for certain format
    By mohammedelbes in forum Advanced Java
    Replies: 3
    Last Post: 01-06-2011, 06:00 PM
  4. regular expressions
    By sozeee in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:58 PM
  5. Regular Expressions in java
    By blue404 in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2008, 03:43 AM

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
  •