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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:16:44+00:00 2026-05-20T12:16:44+00:00

I am referring as a follow up on this question here: Regular expression to

  • 0

I am referring as a follow up on this question here: Regular expression to match two numbers that are not equal

Now my other question scenario is this:

P121324 - T  
P1212 - F - we got this covered in the message on link above (no same "sets")
P1221 - F - now new restriction - not even the reversed digits 12 - 21  

But, the problem now is that the P string can be very long! – like this:

P121315162324  

please notice this is ok since the “sets” are:

12 13 14 15 16 23 24  

Now, I could make this in the code (PHP) by checking if there are repetitions, but I was wondering if this can be done with single regex command?

  • 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-20T12:16:44+00:00Added an answer on May 20, 2026 at 12:16 pm

    Try this:

    ^P(?:([0-9])(?!\1)([0-9])(?!(?:..)*(?:\1\2|\2\1)))*$
    

    If you want the digits to be restricted to [1-6] like in your previous question then change [0-9] to [1-6].

    See it working online: rubular


    Here is a breakdown of the regular expression:

    ^          Start of string/line.
    P          Literal P
    (?:<snip>) Non-capturing group that matches a distinct pair of digits. See below.
    *          Zero or more pairs (use + if you want to require at least one pair).
    $          End of string/line.
    

    Explanation of ([0-9])(?!\1)([0-9])(?!(?:..)*(?:\1\2|\2\1)) – match one pair:

    ([0-9])    Match and capture the first digit. Later refered to as \1.
    (?!\1)     Negative lookahead. The next character must not be the same as \1.
    ([0-9])    Match and capture a digit. Later refered to as \2.
    (?!<snip>) Negative lookahead. Check that the pair doesn't occur again.
    

    Explanation of (?:..)*(?:\1\2|\2\1) – try to find the same pair again:

    (?:..)*       Match any number of pairs.
    (?:\1\2|\2\1) Match either \1\2 or \2\1.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard people referring to this table and was not sure what it was
If I have two objects on the heap referring to each other but they
this is a follow up on my question on paypal integration. I'm working ona
This question is a follow up to my previous Java GC question: Java Garbage
Referring to TLB and maintenance issues ... My question to people (often) using the
I'm referring to distinctions such as in this answer : ...bash isn't for writing
By theoretical computer science topics, I am referring to things such as regular vs
My co-worker posted a question on his blog . He is referring to rendering
As a more general case of this question because I think it may be
[ EDIT - I long since forgot this was here until I got the

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.