Making a RegEx allow anything between two required sections?

RegEx: Allowing for an optional path in the URL

The underlined portion MAY contain chartacters and MAY NOT.

            string regEx = @"^https?://(" + Regex.Escape(redirectWhitelist) + ")_______\\?(goto|returnurl)=https?://(" + Regex.Escape(redirectWhitelist) + ")";

This RegEx requires a certain URL, but I do not want to require that:

            string regEx = @"^https?://(" + Regex.Escape(redirectWhitelist) + ")/openup/UI/Login\\?(goto|returnurl)=https?://(" + Regex.Escape(redirectWhitelist) + ")";

What can I place into the RegEx in place of  "/openup/UI/Login"

So that anything is acceptable, including nothing?

Thanks.
newbiewebSr. Software EngineerAsked:
Who is Participating?
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.

LearnctxEngineerCommented:
So that anything is acceptable, including nothing?

If you want anything to be acceptable, then use the wildcard regex character.

Matches anything 0 or more times between ) and \\?
string regEx = @"^https?://(" + Regex.Escape(redirectWhitelist) + ").*\\?(goto|returnurl)=https?://(" + Regex.Escape(redirectWhitelist) + ")";

Open in new window


Alternatively.

Matches any character 1 or more 0 or 1 times between ) and \\?
string regEx = @"^https?://(" + Regex.Escape(redirectWhitelist) + ")(.+)?\\?(goto|returnurl)=https?://(" + Regex.Escape(redirectWhitelist) + ")";

Open in new window


If you want to be more specific in what is and is not acceptable you'll need to use a class list of acceptable characters (e.g. [a-zA-Z0-9\+-_\/\\\.\?\(\)=\+&\$%@]).
0

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:
thanks
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.