954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regex error

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

Melow
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

do you get an error message?

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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

Melow
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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

Melow
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: