How to use regex to search string between {}?

lampahome pahome.chen at mirlab.org
Fri Aug 23 04:42:41 EDT 2019


I want to parse a path string with multiple files and try to figure out a
one-line way.

If I have path: /home/admin/hello/yo/{h1,h2,h3,h4}

What I thought is use regex.search, but the pattern always failed.

I use below:
import re
path = /home/admin/hello/yo/{h1,h2,h3,h4}
r = re.search('{.}', path)
# r should be ['h1,h2,h3,h4'] but I fail

Why always search nothing?



More information about the Python-list mailing list