I am having trouble understanding this RegEx:

I am having trouble understanding this RegEx:

            string redirectRegex = @"(.*)?\?(.*)?(" + redirectparams + "){1}\\=(.*?[^&]+)?&?(.*)?";

Please break out each element and explain what that element does.

Thanks
newbiewebSr. Software EngineerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
it_saigeConnect With a Mentor DeveloperCommented:
Using http://www.regex101.com:
/
(.*)?\?(.*)?(" + redirectparams + "){1}\\=(.*?[^&]+)?&?(.*)?
/
1st Capturing Group (.*)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\? matches the character ? literally (case sensitive)
2nd Capturing Group (.*)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group (" + redirectparams + "){1}
{1} Quantifier — Matches exactly one time (meaningless quantifier)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
" matches the character " literally (case sensitive)
 + matches the character   literally (case sensitive)
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
 redirectparams matches the characters  redirectparams literally (case sensitive)
 + matches the character   literally (case sensitive)
 " matches the characters  " literally (case sensitive)
\\ matches the character \ literally (case sensitive)
= matches the character = literally (case sensitive)
4th Capturing Group (.*?[^&]+)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.*? matches any character (except for line terminators)
Match a single character not present in the list below [^&]+
&? matches the character & literally (case sensitive)
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
5th Capturing Group (.*)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.* matches any character (except for line terminators)

-saige-
0
 
newbiewebSr. Software EngineerAuthor Commented:
1) I have questions:

? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed

This definition seems to contradicts itself. Why does it not say, "one or more times?" Can you give an example?


2) \\ matches the character \ literally

So, the special character that needs escaping is the = (equal sign)

so it needs an \

I do not understand why it needs \\


3) I do not get the use of &

Please expound on:
Match a single character not present in the list below [^&]+

&? matches the character & literally (case sensitive)
0
 
newbiewebSr. Software EngineerAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.