RegEx in Xpath excluding leading and trailing whitespaces

Ask general questions here.
mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

RegEx in Xpath excluding leading and trailing whitespaces

Post by mrt » Tue Jul 05, 2022 12:38 pm

Dear folks,

I got a RegEx question that drives me nuts, hopefully someone could enlighten me.

I need to select an element by innertext because there are absolutely no other unique attributes but the innertext.
The inner text looks like this (the dots are whitespaces):

Code: Select all

.......
.........CV
......
In the exact same path there is also an element 'SCV' which should NOT match.

so something like

Code: Select all

.../tag[innertext='CV']
obviously does not work because of all the leading and trailing spaces.

Code: Select all

.../tag[innertext~'CV']
also does not work, because it matches 'CV' and 'SCV' (whatever comes first)

So what I am after is to ignore all leading and trailing whitespaces with something like \s* and then do a 'equal' identification instead of the 'contains', which should then be able to differentiate between 'CV' and 'SCV'.

Any ideas?
Would be very much appreciated...

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: RegEx in Xpath excluding leading and trailing whitespaces

Post by mrt » Tue Jul 05, 2022 12:50 pm

Today is my lucky day, found it using word boundaries:

Code: Select all

.../tag[innertext~'^\W*(<the string to match>)\W*$']