Helpful Information
 
 
Category: Regex Programming
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.

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).

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.










privacy (GDPR)