[Python] How can I select a string with the following pattern using RegEx with Python?

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking for specific structures in my text data. One of these is creating many problems; look the following toy sentence:

    "As you can see by reading point a) and b), someone could even use lect. A), B) and Z)."

    My goal is to use a RegEx which can find structures representing items list, where the items are represented with the use of ALPHA+PARENTHESES.

    Even if it might not be the best solution, I thought that one way could be defining the following pattern:

    WORD + ALPHA) + xx + ALPHA) where "xx" represent all the sequence of characters (including symbols and spaces) between ALPHA) and ALPHA) which does not contain more than 3 alpha characters in sequence. How can I do it using RegEx? Anyone with some ideas to deal with such a problem?

    In the shown example I would like to get:

    • "point a) and b)"
    • "lect. A), B) and Z)"

    I have to say I'm not so skilled in using RegEx.

    I hope I made the problem clear. Thanks in advance to anyone who can help!

    Continue reading...

Compartilhe esta Página