string regex manipulation help needed

i have a text in a variable, and need to print 1 line above a text “Error” , so i get the items that are erroring. what tools , add-ons  to use so i get below output  Item4 Item5   from   Item1 Good Item2 Good Item3 Good Item4 Error Item5 Error Item6 Good
2 answers

You can do this with XPath and do retrieve only on those items that have the text attribute "Erorr".



All can be done with string function calls:

Use the find method to get the location of Error. So

find($stringtosearch, 'Error')


The result would be 47. Now you wanted the string before the error so now find the position of Good. Since you need the last occurance of Good before 47 you could use substring for that. We already now the length of the string we want (47) so just use the following command. Note that 0 means start from the biginning.

substring($stringtosearch, 0,47)


You can then use findLast to get the last position of Good.  You can then use substring again but instead of 0 use the value of the position of Good plus 4 for the length of Good to get the result you want.

This way you can cut your  string up untill there are no Errors in you string anymore.