Skip to content Skip to sidebar Skip to footer

Regex: Get Everything After Curly Braces

I got node names from an XML file that contain a namespace: {http://datex2.eu/schema/2/2_0}nodeName From this I would like to trim the namespace, which is in curly braces. So the

Solution 1:

Can be done without regex simply if you assume you want everything after the "}":

  1. With rsplit - take what's after the "}"

    s.rsplit("}")[-1]

  2. More efficiently with rsplit - split at most once

    s.rsplit("}", 1)[-1]

  3. More efficient with rfind, doesn't allocate a string with the prefix we're throwing away

    s[s.rfind("}")+1:]

Solution 2:

Try this:

s = '{http://datex2.eu/schema/2/2_0}nodeName'
search = re.search('{.*}(.*)',s)
print (search.group(1))

Solution 3:

Post a Comment for "Regex: Get Everything After Curly Braces"