Regular Expression Not Matching Correctly

Kumar

Hi I have to match a pattern like below

{digit 0-1 or A}:{digit 0-1 or A}:{digit 0-1 or A}|{digit 0-1 or A}:{digit 0-1 or A}:{digit 0-1 or A}|{digit 0-1 or A}:{digit 0-1 or A}:{digit 0-1 or A}

I am using the following code -

String accMatrixPattern = "\\d{1,1}|[A]:\\d{1,1}|[A]:\\d{1,1}|[A]|[A]:\\d{1,1}|[A]"; 
String accMatrx = "1:A:1|0:1:1|0:1:1";

If I am using only "\\d{1,1}|[A]"; it is working but not combined.

Please suggest How to match Regular Expression

Thanks

Szymon

If you're trying to match just 0, 1 or A in each position, you can use:

String accMatrixPattern = "[01A]:[01A]:[01A]\\|[01A]:[01A]:[01A]\\|[01A]:[01A]:[01A]";

If you want to take values, -1, 0, 1, A:

String accMatrixPattern = "([01A]|-1):([01A]|-1):([01A]|-1)\\|([01A]|-1):([01A]|-1):([01A]|-1)\\|([01A]|-1):([01A]|-1):([01A]|-1)";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related