cancel
Showing results for 
Search instead for 
Did you mean: 

Regex-xpath-how to extract a substring from string?

Occasional Contributor

Regex-xpath-how to extract a substring from string?

I have the following xpath match in my test suite,

 

//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1]

 

Result : 

 

http://news.co.uk:10100/local-news-en-1.0/info

 

I want the result as http://news.co.uk:10100/ 

 

I tried the below xpath expression with reg ex,

 

concat(join(tokenize(//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/@href[1], '/' )[position() < 4],'/'),'/')

 

This i am getting the error as invalid xpath expression.kindly suggest me why this xpath expression is incorrect and help me to form the correct syntax to get the substring properly.

 

I cant write this groovy script to get this..i am facing CDATA error because of http response.

 

So i want the suggestion for xpath+regex

 

Thanks for advance .same problem in ready API too

1 REPLY
Community Leader

Re: Regex-xpath-how to extract a substring from string?

API Summer News

Congratulate last week's winners here:
1. @sanj - $50
2. @Sehuang and @aaronpliu - $35
3. @jhanzeb1 - $15

To do this week:
- Ask product-related questions
- Reply to any questions

Win $50, $35 or $15 gift card!
Winners will be decided next Monday (Aug 27)

Top Kudoed Authors
Are You In?