views:

194

answers:

1

Hi

I have tried to create a regular expression that would match if the input text has max 3 lines of text, at most 10 characters per line, and characters are all uppercase. So this string should match: "AA\n\nAA"

but this shouldn't "A12c"

I thought this would work: (I enabled multiline in Pattern)

(^[A-Z]{0,10}$){0,3}

but it doesn't, it only matches if the text is jut one-liner.

I cannot understand what is wrong with the expression - isn't the {0,3} quantifier applied correclty?

+1  A: 

You forgot to match the line terminator:

(^[A-Z]{0,10}$\r?\n?){0,3}

should work, assuming that the option for ^ and $ to match start/end-of-line and not start/end-of-string is set.

Tim Pietzcker
thanks, that works! I thought the line terminator was implicit when $ was present
Diana