How do I find the string between two special characters?
问题 For example, I need everything in between the two square brackets. File1 [Home sapiens] [Mus musculus 1] [virus 1 [isolated from china]] So considering the above example, I need everything in between the first and last square brackets. 回答1: Regular expressions are the most flexible option. For another approach, you can try string's partition and rpartition methods: >>> s = "[virus 1 [isolated from china]]" >>> s.partition('[')[-1].rpartition(']')[0] 'virus 1 [isolated from china]' 回答2: You