1

I have my code as

Regex regExValue = new Regex(cirtText.Properties.Mask.EditMask);

but i get an exception as

Message : parsing "((www).([a-zA-Z0-9]{1,6}+.+)*[a-zA-Z]{2,6})" - Nested quantifier +.

can anyone let me know the solution?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
shobha
  • 21
  • 1
  • 4

4 Answers4

3

You have two quantifiers {1,6} (between 1 and 6 only) and + (at least 1) here. That's your error. You need to choose one.

[a-zA-Z0-9]{1,6}+

Anyway, you probably meant to write your regex like this:

((www)\.([a-zA-Z0-9]{1,6}\.)*[a-zA-Z]{2,6})
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • if i remove the two + signs then after every 6 character i get a dot and my cursor gets placed after tht. – shobha Dec 28 '10 at 09:01
  • but if i want a dot to appear and my cursor be placed before the dot. so the two + signs are required for me. can u suggest me with anything else? it would be really helpful. – shobha Dec 28 '10 at 09:03
  • +1 for `{1,6}+` which is the actual syntax error the OP needs to fix. – Brian Dec 28 '10 at 18:14
  • @shobha: BoltClock has correctly indicated why your existing code does not work. If you still have issues, you should either edit your existing question or ask a new one. As for the + being required, that makes no sense. `{1,6}+` means "Repeat this 1 to 6 times 1 or more times". In English this is redundant, in a Regex it is illegal (because it is redundant). If you want, you can remove the `{1,6}` instead of the `+` (meaning allow any number of characters instead of 1-6 characters). – Brian Dec 28 '10 at 18:21
1

I don't know C# regex or what you are trying to do (ie: edit, validate,.. etc)
I know Perl, so I'll take a stab at it.
In regex's a period is a meta character. If you want a literal period, you have to escape
it with a '.' The meta period says match any character. If you want a literal period,
and to keep what you have, in Perl you either should not double quote the regex or escape
the escape. A single quote should work fine.
'((www)\.([a-zA-Z0-9]{1,6}+\.+)*[a-zA-Z]{2,6})'

Now, unless you want multiple literal periods, you should get rid of the + quantifier
'((www)\.([a-zA-Z0-9]{1,6}+\.)*[a-zA-Z]{2,6})'

As was said, {n,m} itself is a quantifier. Adding + after it is a double quantifier.
In Perl adding + after a quantifyer implies a possesive condition and is legal starting in version 5.10
So, getting rid of the extra + it is now
'((www)\.([a-zA-Z0-9]{1,6}\.)*[a-zA-Z]{2,6})'

Finally, the * quantifyer implies 0 or more times. Why would you want to match 0 times?
Fixing that it is now
'((www)\.([a-zA-Z0-9]{1,6}\.)+[a-zA-Z]{2,6})'

As an extra, you have a main grouping around everything, a grouping around www, and one
around the middle ([a-zA-Z0-9]{1,6}.)+ which does no good in capture, just in grouping.
If you want to capture the beginning, middle, end, you should add appropriate capture
'((www\.)(([a-zA-Z0-9]{1,6}\.)+)([a-zA-Z]{2,6}))'

Or, in Perl, that would be better written as
'((www\.)((?:[a-zA-Z0-9]{1,6}\.)+)([a-zA-Z]{2,6}))'

  • hey thx so much for ur brief description. but here as u said if i use the regex.... when i atsrt typing i initially get www. and then when i type 6 chars the dot appears and the cursor gets placed after the dot. – shobha Dec 29 '10 at 06:36
  • But i want it to be as... when i type any char after the www. then after 6 chars the dot should appear, but the cursor should be placed before the dot allowing me to type more. so its not working out if use ur regex given. – shobha Dec 29 '10 at 06:38
0

As others have mentioned, having two consecutive quantifiers is meaningless. It looks like you may have meant to say "one or more of these groups of one to six characters"; is it possible that you've left out parenthesis? If that's what you meant, this is easy to resolve:

(note that in .NET regexes, if you actually want a dot you have to escape the period, otherwise it'll match anything)

@"((www)\.(([a-zA-Z0-9]{1,6}+)\.+)*[a-zA-Z]{2,6})"
Ben
  • 6,023
  • 1
  • 25
  • 40
  • Thx for the suggestion.....But i still get the nested quantifies error if i use the above said regex which is not solving my problem. – shobha Dec 29 '10 at 06:39
0

You could visit here link text

to find out how to use a regular expression as a Mask. To be honest, your question isin't about regular expressions. There is some peculariarity about your presentation code that suggests DevExpress implementation of RegEx and Masks. You might want to check there. ie:

DevExpress

For more information on regular expressions, see the "Mask Type: Full Functional Regular Expressions" document in the help documentation of the XtraEditors Library.

You look like you are using DevExpress with .Net's Regex class. But DevExpress has thier own implementation it seems.

Also, the repetitive input via quantifier might be questionable in relation to a mask. Regardless, you could try this but its just a guess:

'www\.(([a-zA-Z0-9]{1,6}\.?)+)*\.[a-zA-Z]{2,6}' 
Community
  • 1
  • 1