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 6935603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:07:28+00:00 2026-05-27T12:07:28+00:00

Being a designer with limited coding experience, I always considered regex to be some

  • 0

Being a designer with limited coding experience, I always considered regex to be some kind of black magic. Recently, I’ve been reading up a bit – and I’m getting pretty intrigued by its possibilities. So I decided to give it a first try in my current php project.

I want to find all URLs of the following structure:

http://[any subdomain, only a-z].domain.com/[any subfolder, can contain a-z,A-Z,0-9,- and _]/

Examples:

  • http://sub.domain.com/A4_3/
  • http://othersub.domain.com/c_44/

My regex:

http://[a-z]*\.domain\.com/[A-Za-z0-9\_\-]*/

My questions:

  • The regex is working, but I’m just wondering whether it could be improved. For instance, I tried adding case insencitive with (i?) but couldn’t get it working.
  • I could only get it working in php if I added double quotes at start and end of the expression, why is that? $ref = preg_replace('"http://[a-z]*\.domain\.com/[A-Za-z0-9\_\-]*/"','',$ref);
  • 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-27T12:07:29+00:00Added an answer on May 27, 2026 at 12:07 pm

    In php regex must be delimited, usualy by / but it can be almost any character.

    The reason why your second attempt works is because you’re using " as delimiter.

    To be case insensitive you have to put the flag i after the second delimiter:

    $ref = preg_replace('"http://[a-z]*\.domain\.com/[A-Za-z0-9\_\-]*/"i','',$ref);
                                                               here ___^
    

    With the i flag there’re no needs for [a-zA-Z] and [a-z] would suffice. Moreover you don’t need to escape the underscore _ in the character class and not the dash - if it’s placed at the first or the last position within the character class

    $ref = preg_replace('"http://[a-z]*\.domain\.com/[a-z0-9_-]*/"i','',$ref);
    

    Note that [a-zA-Z0-9_] can be abbreviated as \w, then your code could look like:

    $ref = preg_replace('"http://[a-z]*\.domain\.com/[\w-]*/"i','',$ref);
    

    Take into account that * stands for 0 or more times, so your regex will match something like:

    http://.domain.com//

    Change * by + that means 1 or more time to be sure you have at least one char for the subdomain and one char for subfolder:

    $ref = preg_replace('"http://[a-z]+\.domain\.com/[\w-]+/"i','',$ref);
    

    And then " is unusual for delimiter, use for example #, ~ or !:

    $ref = preg_replace('#http://[a-z]+\.domain\.com/[\w-]+/#i','',$ref);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes when I'm editing page or control the .designer files stop being updated with
I'm currently working on an app that is being created using Ironspeed Designer. It's
Being new to test based development, this question has been bugging me. How much
Is there any way that I can prevent a designer class from being rebuilt
I've recently noticed that the Visual Studio designer (I'm guessing it's called that) has
My workflow has been to develop models incrementally using EF designer and generating the
The company I work for has recently been hit with many header injection and
I'm developing a WinForms application in C#. I have limited experience in GUI programming,
I'm new in C# but not new to coding --being doing it for almost
As a coder, and not being a designer, I was wondering if there is

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.