0

I need to validate a user input string to match specific pattern using regex in java. user input needs to match the following syntax: sv32i-a- where "sv" is always mandatory followed by 32 or 64, then "i" or "c" then "-" then "a" or "b" then "-" and then " " an empty space and then a possible repetition on the string like (sv32i-a- sv64c-b- ). Just getting confused. Thank you!

public class StringValidation {
    static boolean result = true;

    //Help needed here. 
    static String syntax = "^rv\\d{2}$"; //Code goes here but not sure about the syntax..

    public static boolean isTrue(String stringToValidate) {
        result = stringToValidate.matches(syntax);

        return result;
    }
}

1 Answer 1

2
sv           here "sv" is always mandatory
(?:32|64)    followed by 32 or 64,
[ic]         then "i" or "c"
-            then "-"
[ab]         then "a" or "b"
-            then "-"
             and then " " an empty space
(?:xxx)+     and then a possible repetition on the string like (sv32i-a- sv64c-b- )

So: (?:sv(?:32|64)[ic]-[ab]- )+

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.