[Python] Match all possible combinations of words using regex

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

  1. Stack

    Stack Membro Participativo

    I've been struggling whole day to get what I want. Maybe you can help me.

    Let's say I have a string DT JJ NN IN JJ JJ NN NNS IN, ideally, for needed result I would write a regular expression something like this:

    (<NN.*> +)|(<NN.*> +<JJ.*> *)|(<JJ.*> *<NN.*> +)


    I want to get a result like all possible combinations, by the example would be like:

    1. NN
    2. NN
    3. NNS
    4. JJ NN
    5. JJ JJ NN
    6. JJ JJ NN NNS
    7. JJ NN
    8. JJ NN NNS
    9. NN NNS

    Maybe I am seeking for impossible or should change an attitude. I don't know. Please share any ideas.

    Thanks in advance!

    Continue reading...

Compartilhe esta Página