Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have code something like that below;

private StringDictionary Parse( string queryString ) {
		queryString = queryString + "&";
		StringDictionary outc = new StringDictionary();
		Regex r = new Regex(@"(?[^=&]+)=(?[^&]+)&", RegexOptions.IgnoreCase | RegexOptions.Compiled);
		IEnumerator enums = r.Matches(queryString).GetEnumerator();
		while ( enums.MoveNext() && enums.Current != null ) {
			outc.Add(( (Match) enums.Current ).Result("${name}"), ( (Match) enums.Current ).Result("${value}"));
		}
		return outc;
	}


and i am gettin an error somthing like that below:

parsing "(?[^=&]+)=(?[^&]+)&" - Unrecognized grouping construct.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: parsing "(?[^=&]+)=(?[^&]+)&" - Unrecognized grouping construct.

Does anyone help me any help greatly appreciated. Thanks for all you.
Posted
Comments
[no name] 19-Mar-11 11:48am    
Perhaps a tool like Expresso, http://www.ultrapico.com/Expresso.htm, would help you.
Paul Goldenberg 19-Mar-11 11:54am    
The ? characters in the regex are the cause of the syntax error. What will your source query strings look like and what are you trying to capture?

1 solution

If you run your regex through Expresso it tells you "Illegal Group Syntax"

(?...) is not a valid group. Did you mean (?<Name>...) which is a named group? Or (...) which is a numbered group?

Either way, it is difficult to see exactly what you are trying to match:
[^=&amp;]+
will match one or more of any character which is not an ampersand or equals: but you them follow that with an equals so any occurance of ampersand will not match anyway: the equals test will fail.

If what you want is to match data=moredata& then all you need is
(.+?)=(.+?)&
Or
(?<PreEquals>.+?)=(?<PostEquals>.+?)&
if you prefer named groups.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900