I'm looking to split a string into 5 parts, and assigning each part to separate variables. I am assuming the best option is to use Regex (and I'm complete beginner with regards to Regex).
First part: Everything up to the third-to-last number. Second part: The third-to-last number. Third part: Text between the third-to-last number and the last number. Fourth part: The last number. Fifth part: Everything after the last number.
From what I can work out the following Regex formula would split is accordingly:
(.*)(\d)(.*)(\d)(.*)(\d)(.*)
The result being: First part: //*[@id='app']/div[2]/div[2]/div[3]/div/div[10]/div[2]/div/div[4]/div[2]/div/div[8]/div/div Second part: 8 Third part: /div[3]/div Fourth part: 3 Fifth part: /div/div
Having never used Regex before in KM I'm now kid of lost on how I use the formula to assign those parts to the five variables.
The above answer is both correct and meaningless, because it's not related to KM except tangentially. I'm pretty sure it's spam, and have flagged it as such.
Going back to your issue, I have a question at the very top level. You say you want the first part to be everything up to the third-to-last number, and then your example says that number is 2. But isn't the third-to-last number 8, not 2? 3 is the last number, then 2 is second-to-last, and 8 is third-to-last. Which one is it you need to split at?
It also looks like you want to lose the brackets surrounding the numbers? Perhaps it's time to take a big step backwards, as there are potentially simpler solutions at hand.
What is it you're trying to accomplish? What part(s) of that string do you need to keep and work with as variables? Each and every separate part, or only certain parts? The more detail you can provide about what you're trying to do and what you actually need from the string, the better solution you'll get here.
Thank you everyone for taking a look at this. I have now worked it out, thanks to ChatGP no less!
Solution below. What I wasn't sure of was how to get the Regex into variable, but now I understand the way to do that is via the Search Variable using Regular Expression action.
The reason for requiring this is that I need to click on 16 different images in a web form.
That's not particularity difficult to do, but the reason for wanting to do it this way was because the starter Xpath regularly changes.
However the two relevant numbers in the xpath, the third last and the last, are always in the same position. Those numbers refer to row and column of the images. By changing those two numbers I can control which image is clicked on.
So now when the xpath changes, rather than have to change 16 different variables manually I can just paste in the new xpath and have all the other variables calculate the new xpaths, as such...
...which would be shorter, except that while you can set a pseudo-array element from a "Set Variable to Text" action:
...you don't seem to be able to do that directly in the "S'n'R":
...which is a shame.