-1

I have an string containing multiple words, breaks etc. // The String containts at least two URL, where I need to get the first one and extract the ending.

String:

Topic: Scall

Some text. Some words. Some some....

Link1: https://test.com/cancel/AA7ES34QSAGF563N
Link2: https://test.com/move/AA7ES34QSAGF563N

I have to find Link1 -> https://test.com/cancel/AA7ES34QSAGF563N and then I need the last part -> AA7ES34QSAGF563N

The string changes often. So I need to find a solution which exactly finds a link starting with https://test.com/cancel/ (I got it working to find THE first link, but if another link is placed in the string, this would'nt work anymore). There is also a chance that the last link is another link which I don't need. So searching only for the last link isn't an option.

I am using zapier, and I have only the option to find the value with one line of regex:

enter image description here

Could someone help me with that?

1 Answers1

0

Assuming you already have your link in a string variable, you can use the built-in function split() along slice notation to get what you want.

>>> link = "https://test.com/cancel/AA7ES34QSAGF563N"
>>> id = link.split("/")[-1]
AA7ES34QSAGF563N

Using regex, you could achieve the same result with [^\/]+$ (working example: https://regex101.com/r/vVWtD0/1)

Antoine Delia
  • 1,728
  • 5
  • 26
  • 42