Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:57:35+00:00 2026-05-31T05:57:35+00:00

I have a URL pattern that needs to contain either APPLES or ORANGES in

  • 0

I have a URL pattern that needs to contain either APPLES or ORANGES in it, no other value. Optionally, it can also have query parameters. I’ve tried a number of RegEx patterns, but I just can’t get a pattern that will respect the strict match.

Sample URLs

Good

http://www.website.com/en/pages/APPLES
http://www.website.com/en/pages/APPLES?k=v
http://www.website.com/en/pages/ORANGES?k=v&k2=v2
http://www.website.com/en/pages/ORANGES

Bad

http://www.website.com/en/pages/APPLES???k=v
http://www.website.com/en/pages/APPLES?k=v=v
http://www.website.com/en/pages/APPLESORANGES
http://www.website.com/en/pages/1APPLES
http://www.website.com/en/APPLES

Attempted RegEx Patterns (well, at least the best attempts)

(http://*.*.website*.*.com/*.*/pages(/APPLES)|(/ORANGES)[\?]*.*)
(http://*.*.website*.*.com/*.*/pages(/APPLES|/ORANGES)[\?]*.*)

If you’re curious, I intentionally want to allow any sub-domain, suffix after “website” (for different environments), and any path between .com/ and /pages, hence the use of . in a number of places.

What would be the best way to achieve this?

**Edit: Final Answer**

My final answer was merged from mathematical.coffee and fardjad.

^https?://.*\.website\b.*\.com/.*/pages/(APPLES\b|ORANGES\b)((\?\w+=\w+)(&?\w+=\w+)*)?$

The single limitation I’ve discovered is that it will not allow a few valid characters (.~_-%+) in the query string parameter key=value pairs (see: http://en.wikipedia.org/wiki/Query_string#Structure). This isn’t an issue for me as I’m matching against a string returned from .NET’s Uri class, so I know the URL is well-formed overall.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:57:38+00:00Added an answer on May 31, 2026 at 5:57 am

    I think the *.* should be .*:

    http://.*\.website\b.*\.com/.*/pages/PAGE[12](\?[^=]+=[^&=]+(&[^=]+=[^=&]+)*)?
    

    Explanation:

    http://      # just http://
    .*\.         # any thing, just make sure it's followed by '.'
    website\b    # website, the whole word
    .*\.com      # anything between website and .com
    /.*/pages/   # anything between the .com and the pages
    PAGE[12]     # PAGE1 or PAGE2
    (\?          # opening bracket and '?' (query string)
    [^=]+        # the key: i've said it can't include =
    =            # =
    [^=&]+       # the value: i've said it can't include = or &
    (&           # opening bracket and '&' for next part of query string
    [^=]+=[^=&]+ # key=value pair, same regex as before
    )*           # 0 or more of these (the &key=value)
    )?           # the entire query string is optional.
    

    NOTE – there are usually problems parsing query strings with regex and making sure it’s a syntactically valid regex.

    For example, in the regex I supplied above, I’ve said that the value in &key=value can’t have an ampersand in it. But it could be an escaped entity, like &, which is legal.

    You’ll always suffer from this sort of problem when you try to parse syntax with regex. It’s a risk you’ll have to take.

    Alternatively, I am sure there is a C# module to parse URLs (many other languages have these), and they take care of all these special cases for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to match url pattern that has optional segments. I have URL-s
I'm trying to implement java like url pattern matching in php. Suppose i have
I wrote a filter that needs to be invoked every time a url on
I have the following urls that need mapping to two different servlets. Can anyone
I have my Servlet responding on the everything / url-pattern. Inside I need to
I have a web application secured with Spring Security that needs two separate login
I have a search Api I'm working on that needs to return search results
I have updated my url pattern from: (r'^(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'), to (r'^issue/(?P<id>[0-9]+)/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'), So I'm
I have url like this /cp/foo-bar/another-testing how to parse it with the pattern /cp/{0}-{1}/{2}
I have URL like: http://example.com#something , how do I remove #something , without causing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.