How to find text between brackets of a string in Python

Finding text between a set of brackets returns the first string that lies between the first open bracket and first closed bracket – if such a string exists.

Solution for How to find text between brackets of a string in Python : You can use str.find() to find text between brackets of a string Call string.find(“[“) to find the index of the first occurence of “[” in string. Then call string.find(“]”) to find the index of the first occurence of “]” in string. Lastly, use the two indices to slice the string between the opening and closing brackets, string[first + 1:second] where first and second are the indices obtained from the previous function calls.


how-to-find-text-between-brackets-of-a-string-in-python