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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:39:33+00:00 2026-06-12T00:39:33+00:00

Could someone help us with a regular expression in order to detect repeated patterns

  • 0

Could someone help us with a regular expression in order to detect repeated patterns inside a URL string? The goal is obviously to detect malformed weird URLs.

For example, the following URLs are alright:

http://www.somewhere.com/help/content/21/23/en/
http://www.somewhere.com/help/content/21/24/en/
http://www.somewhere.com/help/content/21/64/en/
http://www.somewhere.com/help/content/21/65/en/
http://www.somewhere.com/help/content/21/67/en/

While this this ones, are incorrect, and should be tagged:

http://www.somewhere.com/help/content/21/content/1/54/en/
http://www.somewhere.com/help/content/21/content/1/62/en/
http://www.somewhere.com/help/content/21/content/8/52/en/

Since content is repeated twice. So far we have been solving this using parse_url and explode, but it looks quite inefficient!

As well, I’m aware that there might be many URLs that repeat a number in the path, or some other value, so any suggestions to solve this issue would be more than welcome.

Thanks a lot!

For a better comprehension of the issue, you can visit the following link and click on “Administrador MySQL”:

http://www.elserver.com/ayuda/content/21/65/es/

  • 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-06-12T00:39:42+00:00Added an answer on June 12, 2026 at 12:39 am

    Assuming you have a file (testdata.txt) which contains a list of URLs, one per line, the following tested script will extract those URLs having (at least) one repeated path segment:

    <?php // test.php Rev:20120924_0800
    $re = '%
        ^                  # Anchor to start of line.
        (?:[^:/?#\s]+:)?   # URI scheme (optional).
        (?://[^/?#\s]*)?   # URI Authority (optional).
        (?:/[^/?#\s]*)*?   # URI path segments (before repeats).
        /([^/?#\s]+)       # $1: Repeated URI path segment.
        (?:/[^/?#\s]*)*?   # URI path segments (between repeats)
        /\1                # $1: Repeated URI path segment.
        (?:/[^/?#\s]*)*    # URI path segments (after repeats).
        (?:\?[^#\s]*)?     # URI query (optional).
        (?:\#\S*)?         # URI fragment (optional).
        $                  # Anchor to end of line.
        %mx';
    $text = file_get_contents('testdata.txt');
    if (preg_match_all($re, $text, $matches)) print_r($matches[0]);
    else echo("no matches!");
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone help me to write a function that checks if a string is
I'm not really good with regular expressions, so I'm hoping someone could help come
I am trying to learn regular expressions and was hoping someone could help me
I hate regular expressions and I was hoping someone could help with a regualar
$content = preg_match('/[flv[^/]]+:(.*?)[^/]]*/]','', $content); Could someone give me the regular expression for extracting [flv:example.flv
Can someone help me with a regular expression that would help me do this.
Could someone help me to add A-atype B-btype C-ctype ONLY as a legend to
Could someone help me to write a logic that converts a ID array to
could someone help me on this problem, i want to access facebook API through
could someone help me with the regex pattern that i could use to match

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.