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

The Archive Base Latest Questions

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

I want to parse the 2 digits in the middle from a date in

  • 0

I want to parse the 2 digits in the middle from a date in dd/mm/yy format but also allowing single digits for day and month.

This is what I came up with:

(?<=^[\d]{1,2}\/)[\d]{1,2}

I want a 1 or 2 digit number [\d]{1,2} with a 1 or 2 digit number and slash ^[\d]{1,2}\/ before it.

This doesn’t work on many combinations, I have tested 10/10/10, 11/12/13, etc…

But to my surprise (?<=^\d\d\/)[\d]{1,2} worked.

But the [\d]{1,2} should also match if \d\d did, or am I wrong?

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

    On lookbehind support

    Major regex flavors have varying supports for lookbehind differently; some imposes certain restrictions, and some doesn’t even support it at all.

    • Javascript: not supported
    • Python: fixed length only
    • Java: finite length only
    • .NET: no restriction

    References

    • regular-expressions.info/Flavor comparison

    Python

    In Python, where only fixed length lookbehind is supported, your original pattern raises an error because \d{1,2} obviously does not have a fixed length. You can “fix” this by alternating on two different fixed-length lookbehinds, e.g. something like this:

    (?<=^\d\/)\d{1,2}|(?<=^\d\d\/)\d{1,2}
    

    Or perhaps you can put both lookbehinds as alternates of a non-capturing group:

    (?:(?<=^\d\/)|(?<=^\d\d\/))\d{1,2}
    

    (note that you can just use \d without the brackets).

    That said, it’s probably much simpler to use a capturing group instead:

    ^\d{1,2}\/(\d{1,2})
    

    Note that findall returns what group 1 captures if you only have one group. Capturing group is more widely supported than lookbehind, and often leads to a more readable pattern (such as in this case).

    This snippet illustrates all of the above points:

    p = re.compile(r'(?:(?<=^\d\/)|(?<=^\d\d\/))\d{1,2}')
    
    print(p.findall("12/34/56"))   # "[34]"
    print(p.findall("1/23/45"))    # "[23]"
    
    p = re.compile(r'^\d{1,2}\/(\d{1,2})')
    
    print(p.findall("12/34/56"))   # "[34]"
    print(p.findall("1/23/45"))    # "[23]"
    
    p = re.compile(r'(?<=^\d{1,2}\/)\d{1,2}')
    # raise error("look-behind requires fixed-width pattern")
    

    References

    • regular-expressions.info/Lookarounds, Character classes, Alternation, Capturing groups

    Java

    Java supports only finite-length lookbehind, so you can use \d{1,2} like in the original pattern. This is demonstrated by the following snippet:

        String text =
            "12/34/56 date\n" +
            "1/23/45 another date\n";
    
        Pattern p = Pattern.compile("(?m)(?<=^\\d{1,2}/)\\d{1,2}");
        Matcher m = p.matcher(text);
        while (m.find()) {
            System.out.println(m.group());
        } // "34", "23"
    

    Note that (?m) is the embedded Pattern.MULTILINE so that ^ matches the start of every line. Note also that since \ is an escape character for string literals, you must write "\\" to get one backslash in Java.


    C-Sharp

    C# supports full regex on lookbehind. The following snippet shows how you can use + repetition on a lookbehind:

    var text = @"
    1/23/45
    12/34/56
    123/45/67
    1234/56/78
    ";
    
    Regex r = new Regex(@"(?m)(?<=^\d+/)\d{1,2}");
    foreach (Match m in r.Matches(text)) {
      Console.WriteLine(m);
    } // "23", "34", "45", "56"
    

    Note that unlike Java, in C# you can use @-quoted string so that you don’t have to escape \.

    For completeness, here’s how you’d use the capturing group option in C#:

    Regex r = new Regex(@"(?m)^\d+/(\d{1,2})");
    foreach (Match m in r.Matches(text)) {
      Console.WriteLine("Matched [" + m + "]; month = " + m.Groups[1]);
    }
    

    Given the previous text, this prints:

    Matched [1/23]; month = 23
    Matched [12/34]; month = 34
    Matched [123/45]; month = 45
    Matched [1234/56]; month = 56
    

    Related questions

    • How can I match on, but exclude a regex pattern?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm want to parse a custom string format that is persisting an object graphs
I want to download and parse webpage using python, but to access it I
I want to parse some kind (or pure) XML code from a QString. My
I want to parse a dtd file and use the info I get from
I want to parse some XML-file in Qt, but that file is located at
I want to parse a config file sorta thing, like so: [KEY:Value] [SUBKEY:SubValue] Now
I want to parse some HTML in order to find the values of some
I want to parse a web page in Groovy and extract all of the
I want to parse an Apache access.log file with a python program in a
In my C++ program I want to parse a small piece of XML, insert

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.