#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Convert Java RegEx to JavaScript RegEx


    Hi
    I need a help in finding out an equivalent javascript regex representation to my java regex expression

    Below is my code in java:
    public static final String postcodePatternString =
    "(((" +
    "([A-Z&&[^QVX]])" +
    "(" +
    "((\\d)|(\\d\\d)|(\\d[ABCDEFGHJKSTUW]))|" + |
    "(([A-Z&&[^IJZ]]\\d)(((\\d)|([ABEHMNPRVWXY]))?))" +
    "))"+
    "(" + " " +
    "(\\d[A-Z&&[^CIKMOV]][A-Z&&[^CIKMOV]]))" +")"+
    "|(" +
    "([A-Z&&[^QVX]])" + //A
    "(" +
    "((\\d)|(\\d\\d)|(\\d[ABCDEFGHJKSTUW]))|" + |
    "(([A-Z&&[^IJZ]]\\d)(((\\d)|([ABEHMNPRVWXY]))?))" +
    "))" + "(\\d[A-Z&&[^CIKMOV]][A-Z&&[^CIKMOV]]))"+
    "|(GIR 0AA)" +
    "|(GIR0AA)"
    ;

    CAN any one tell me how to convert this is in to equivalent javascript RegEx?

    Any help is highly appreciated, i need it urgently.

    Thanks.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,114
    Rep Power
    9398
    Dear Lord. You sure that's a regex and not some obfuscated Java code?

    Have you tried using it without any adjustments? You need to wrap the whole thing in /.../s if you want it done natively, or you can use the RegExp class (in a very logical manner).
  4. #3
  5. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by vijayprasad
    Hi
    I need a help in finding out an equivalent javascript regex representation to my java regex expression

    Below is my code in java:
    public static final String postcodePatternString =
    "(((" +
    "([A-Z&&[^QVX]])" +
    "(" +
    "((\\d)|(\\d\\d)|(\\d[ABCDEFGHJKSTUW]))|" + |
    "(([A-Z&&[^IJZ]]\\d)(((\\d)|([ABEHMNPRVWXY]))?))" +
    "))"+
    "(" + " " +
    "(\\d[A-Z&&[^CIKMOV]][A-Z&&[^CIKMOV]]))" +")"+
    "|(" +
    "([A-Z&&[^QVX]])" + //A
    "(" +
    "((\\d)|(\\d\\d)|(\\d[ABCDEFGHJKSTUW]))|" + |
    "(([A-Z&&[^IJZ]]\\d)(((\\d)|([ABEHMNPRVWXY]))?))" +
    "))" + "(\\d[A-Z&&[^CIKMOV]][A-Z&&[^CIKMOV]]))"+
    "|(GIR 0AA)" +
    "|(GIR0AA)"
    ;

    CAN any one tell me how to convert this is in to equivalent javascript RegEx?

    Any help is highly appreciated, i need it urgently.

    Thanks.
    That is not a valid String literal in Java. There are some '|' characters outside of it.
    To convert it, just print it out in a small Java application: that way you loose the double escapes and can create a JS-regex of it.

IMN logo majestic logo threadwatch logo seochat tools logo