Search code examples
regexspotfire

Regex on Spotfire- Returning the right side of a condition


Is there any way to return the right side of a specific word? For example, [column 1] is written in a consistent form, all the way up to a point. After that point, there exists a location name.

examples of column 1 values (length can vary):

[column 1]= "Annual Inspection PM Location 12"

[column 1] = "Annual Inspection PM Facility abc"

[column 1]= "Annual Inspection PM Spot 1"

All in all, I would like to know if there's a regex expression that I can use in Spotfire to dissect the first part "Annual Inspection PM" from the "Location". The goal is to be able to return the "location"/right side of [column 1] after the word "PM".

This is what I've got so far, but it's not working for me:

RXReplace([scheduled_maintenance_description],"(PM\b)","$","")


Solution

  • Looking at RXReplace on this page Text Functions you could using a capture group (group 1), and use that group in the replacement using $1 as the notation:

    RXReplace([scheduled_maintenance_description],".*\\bPM (.+)","$1","")
    

    The pattern matches:

    • .* Match the whole line
    • \\bPM A word boundary to prevent a partial word match, then match PM
    • (.+) Capture group 1, match 1 or more times any character

    You can see an example of the replacements at this regex101 demo.