Extract state machine name from arn as a variable

Hi,
I we are using grafana 8.2.0.

I am trying to show and use StateMachine name as a variable but can only use corresponding ARN.

I have defined a variable as following:
DataSource: CloudWatch
Name: StateMachineArn
Query: dimension_values($region,AWS/States,ExecutionsFailed, StateMachineArn)

I successfully fetches all state machine ARNs, for ex:

arn:aws:states:us-east-1:123456:stateMachine:sm-1
arn:aws:states:us-east-1:123456:stateMachine:sm-2

I would like to have a variable that has only state machine names, i.e: sm-1, sm-2

I have tried using regex but it only provided additional filtering on the arns not extraction of the substring.

Many thanks

Victor

I have ended up with the following options that work:
regex: /arn:aws:states:us-east-1:123456:stateMachine:(.*)/
regex: /arn:aws:states:us-east-1:123456:stateMachine:(?<text>[^]+)/g

The trick is to use regex capture group for extracting as explained here.