mercredi 1 décembre 2021

Python -- extracting specific substring motifs/patterns from a string [closed]

I want to extract these specific substrings from a string. These are a few couple examples below, but ultimately I have many input strings that are similar. I have tried a substring "frameshift" method but the issue is that I get many undesirable output strings ex. ...(((((.....)))))... --> (((((.....))))), ((((.....)))), (((.....))), ((.....)), and (.....) (this is not desirable). As you can see in the patterns below, I need an equal number of open/close parenthesis and no trailing periods in the substrings.

Example 1

Input String: ..(((...(((((.(((.....((.................))..))).))))).)))..

Desired Extracted Output Substring(s): (((...(((((.(((.....((.................))..))).))))).)))

Example 2

Input String: (((((.((.((..............))..)).)))))(((((.....)))))........

Desired Extracted Output Substring(s): (((((.((.((..............))..)).)))))(((((.....))))) AND (((((.((.((..............))..)).))))) AND (((((.....)))))

Example 3

Input String: ........(((((.......................((((((...))))))...))))).

Desired Extracted Output Substring(s): (((((.......................((((((...))))))...)))))

Aucun commentaire:

Enregistrer un commentaire