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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
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-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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)
newbiewebSr. Software EngineerAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.