Hy

I want to validate expression as such:

AO:10
EM:1
IO:102
AO:SA
EM:SA,AKA,LLMN

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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.