I have a scenario where I need to fetch a particular pattern from the string using regular expression.
The string looks like below:
${text} = Slot 0 l 5 3 24+6
Slot 1 l 3 16 10
Slot 3 l 4 3 32
Slot 8 l 2 3
Slot 9 l 1 3
Here, I need to fetch only
Slot 0
Slot 1
Slot 3
Slot 8
Slot 9
How do I do this?
I have tried using the keywords 'Replace String Using Regexp' and 'Get Regexp Matches' for the same.
${text}= String.Replace String Using Regexp ${response} [^Slot\\s+\\d], ${EMPTY}
The result was:
${text} = Slot 0 l 5 3 24+6 Slot 1 l 3 16 10 Slot 3 l 4 3 32 Slot 8 l 2 3 Slot 9 l 1 3 –
And, Get Regexp Matches gives the below result:
${matches}= String.Get Regexp Matches ${response} [Slot\\s+\\d]
The result:
${matches}= ['S', 'l', 'o', 't', ' ', '0', ' ', ' ', ' ', 'l', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '5', ' ', '3', ' ', ' ', '2', '4', '+', '6', '\r', '\n', 'S', 'l', 'o', 't', ' ', '1', ' ', ' ', ' ', 'l', ' ', ' ... –
[] Matches a single character from the list- you don't need that, you want a match on the whole substring.KEYWORDcomments (they are fairly unreadable) and add them into the question via the edit feature, thanks.