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

  • Home
  • SEARCH
  • 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 5963649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:17:26+00:00 2026-05-22T19:17:26+00:00

Due to limitations in my script, I’ve come across a problem where I need

  • 0

Due to limitations in my script, I’ve come across a problem where I need to make sure a string matches one of two regex patterns while only calling preg_match() once.

Here’s some of my code:

public static function get_file_host_from_link($link)
{
    foreach(Filehosts::$file_hosts as $key => $val)
    {
        if(preg_match("#{$val["regex"]}#", $link))
        {
            // We have a match, return this file host information
            return $key;
        }
    }
    // We've looped through all the file hosts and it hasn't matched,
    // return false
    return false;
}

Now, the problem with matching Fileserve.com URL’s is that there can be two types of valid URL structures. One of them is:

http://www.fileserve.com/file/aHd8AHD

and the other:

http://www.fileserve.com/file/zR8VJVM/file_name.zip

At the moment, I can match the first structure perfectly fine using this regex: ^http://www.fileserve.com/file/[a-zA-Z0-9]+$ but I also need to match the other URL structure using something like this: http://www.fileserve.com/[a-zA-Z0-9]+/[a-zA-Z0-9_-\.]+$. How can I do this with my existing code and only calling preg_match() once? I thought about something like this:

(^http://www.fileserve.com/file/[a-zA-Z0-9]+$|http://www.fileserve.com/[a-zA-Z0-9]+/[a-zA-Z0-9_-\.]+$)

which to my knowledge means “match the first regex pattern OR the second one”, but I have no idea if that’d work.

Thanks!

  • 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-22T19:17:27+00:00Added an answer on May 22, 2026 at 7:17 pm

    The following should work:

    ^http://www.fileserve.com/file/[a-zA-Z0-9]+(/[-a-zA-Z0-9_\.]+)?$
    

    The ? after everything in the parentheses makes it optional.

    Also, note that the character class [a-zA-Z0-9_-\.] is invalid because - specifies a range unless it is escaped or at the start.

    You either want [-a-zA-Z0-9_\.] or [a-zA-Z0-9_\-\.] (I used the first in my answer).

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

Sidebar

Related Questions

This problem relates to report design in BIRT. Due to limitations in the data
Due to some datastorage limitations (noSQL) I need to store images as strings. How
I'm using an older version of ASP.NET AJAX due to runtime limitations, Placing a
Due to repetitive errors with one of our Java applications: Engine engine_0: Error in
Due to some limitations on the place files are being placed, I would like
I need to write a script to do the following: Monitor a queuing system,
Unfortunately, due to the limitations of our Unix Tru64 environment, I am unable to
(working in AS2.0 due to player limitations) In my flash application I draw in
Due to the limitations of the current test users graph api, the bugged platform
I'm currently developing a webinterface for XBMC witch contains ajax. Due the limitations of

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.