Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Python

r"
^arn:(?P<Partition>[^:\n]*):(?P<Service>[^:\n]*):(?P<Region>[^:\n]*):(?P<AccountID>[^:\n]*):(?P<Ignore>(?P<ResourceType>[^:\/\n]*)[:\/])?(?P<Resource>.*)$
"
gm

Description

A pattern to parse Amazon Web Services ARNs into their varying components:

  • Partition
  • Service
  • Region
  • AccountID
  • ResourceType (optional - empty string is missing)
  • Resource
Submitted by Arnoud - 8 years ago