I want to validate expression as such:


so on...

I'm noe to Regex and i came out with the following function:

public void checkFormat(String line) {
        String expression = "^[ACEILMNOU.]{2}+\\B[:]{1}+\\w{2,4}+";
        Pattern subscriptionExpretion = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = subscriptionExpretion.matcher(line);

        if(matcher.matches()) {
            System.out.println("matches " + line);
        } else {
            System.out.println("doesn't match " + line);

witch doesn't work... anyone has a clue on how to make it work?

Thank you

Recommended Answers

do you get an error message?

Jump to Post

All 4 Replies

do you get an error message?

no... the regex i wrote doesn't work properly

You need to break up the regex you have posted and explain your reasoning behind putting the constructs which are there in your regex. Also, instead of posting "sample data" for the pattern you can looking for, it would be much for helpful for your own sake to frame the requirements in words. An e.g. the regex should accept any two alphabets followed by a colon and one or more digits.

I solved my problem, but not with regex, thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.