I was running into somethin the other day where I was trying to extract a serial number from a URL, which is formatted like this:
www.site.com/XYZ/.../abcdef-1234567
The output serial number is: XYZ-1234567
I was dismayed to find I couldn't just use regex to grab the parts I cared about. I instead had to do a far more complicated thing that involved one calculate with a regex to determine what the XYZ was, then another two to grab the end digits with substring and calculating the length of the URL.
| type | name | calculation |
| calculate | issuecalc1 | if(regex(${issuelink}, '^https:\/\/.com.*-type1'), "Type1", "") |
| calculate | issuecalc2 | if(regex(${issuelink}, '^https:\/\/.com.*-type2'), "Type2", "") |
| calculate | issuecalc3 | if(regex(${issuelink}, '^https:\/\/.com.*-type3'), "Type3", "") |
| select_one issuetype | issuetype | coalesce(coalesce(${issuecalc1}, ${issuecalc2}), ${issuecalc3}) |
| calculate | issenoindex | string-length(${issuelink})-10 |
| issueno | issueno | concat(${issuetype}, substr(${issuelink}, ${issuenoindex}, string-length(${issuelink})) |
I probably could have done this more efficiently, but it would have been a snap if I could have just used a regex to extract the two groups I cared about.
Please add in greater regex capability.
Relevant: Add functions like REGEXEXTRACT or even basic subs... - Esri Community