this my xpath
//dns:tbody//dns:td[1][#rowspan="1"]/text()
I want to find a solution how can make the attribute rowspan #rowspan=" only number " accept just number
I'm looking for solution regular expression in XPath 1.0
Regexp =^[0-9]*$
my problem I don't know how to integrate the regex with XPath1.0 or any other solution
You can use a workaround that tests:
if the text is a number (with the number() function)
if the text doesn't start with - (with starts-with())
if the text doesn't contain the dot (with contains())
like that:
//dns:tbody//dns:td[1][string(number(#rowspan))!='NaN'][not(starts-with(#rowspan, '-'))][not(contains(#rowspan, '.'))]/text()
or
//dns:tbody//dns:td[1][not(string(number(#rowspan))='NaN' or starts-with(#rowspan, '-') or contains(#rowspan, '.'))]/text()
Try to use below solution instead of regex:
//dns:tbody//dns:td[1][number(#rowspan)<=0 or number(#rowspan)>0]/text()
This should match #rowspan with int value
Some XPath implementations allow you to supply your own functions. You will need to check the documentation on your XPath implementation.
Java: http://xml.apache.org/xalan-j/xpath_apis.html#functionresolver
Related
I have a challenge getting the desired result with RegEx (using C#) and I hope that the community can help.
I have a URL in the following format:
https://somedomain.com/subfolder/category/?abc=text:value&ida=0&idb=1
I want make two modifications, specifically:
1) Remove everything after 'value' e.g. '&ida=0&idb=1'
2) Replace 'category' with e.g. 'newcategory'
So the result is:
https://somedomain.com/subfolder/newcategory/?abc=text:value
I can remove the string from 1) e.g. ^[^&]+ above but I have been unable to figure out how to replace the 'category' substring.
Any help or guidance would be much appreciated.
Thank you in advance.
Use the following:
Find: /(category/.+?value)&.+
Replace: /new$1 or /new\1 depending on your regex flavor
Demo & explanation
Update according to comment.
If the new name is completely_different_name, use the following:
Find: /category(/.+?value)&.+
Replace: /completely_different_name$1
Demo & explanation
You haven't specified language here, I mainly work on python so the solution is in python.
url = re.sub('category','newcategory',re.search('^https.*value', value).group(0))
Explanation
re.sub is used to replace value a with b in c.
re.search is used to match specific patterns in string and store value in the group. so in the above code re.search will store value from "https to value" in group 0.
Using Python and only built-in string methods (there is no need for regular expressions here):
url = r"https://somedomain.com/subfolder/category/?abc=text:value&ida=0&idb=1"
new_url = (url.split('value')[0] + "value").replace("category", 'newcategory')
print(new_url)
Outputs:
https://somedomain.com/subfolder/newcategory/?abc=text:value
I have the following xpath match in my soapui test suite ,
//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/#href[1]
Result :
http://shortness.com:101115/localnewsv1/info
I want the expected result as below (it should take the result from http to till the third /)
http://shortness.com:101115/
I have tried the following xpath combined with regular expression
tokenize(/html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/#href[1], ' ' )[matches(., 'http://+w[a-zA-Z0-9.]+d{*}+/')
This gives me an invalid expression in the result.if you have idea point the issue or suggest.
Screenshot for the issue
For this markup,
<a href="http://shortness.com:101115/localnewsv1/info"/>
this XPath 2.0 expression (make sure your library supports XPath 2.0),
concat(join(tokenize(/a/#href, '/' )[position() < 4],'/'),'/')
will return
http://shortness.com:101115/
as requested.
I guess that d{*} might have a meaning in some regex dialects but it has no meaning (and is invalid) in the XPath 2.0 regex dialect.
I have solr field stored as -
record1 --> colorDimension : "Purple|91"
record2 --> colorDimension : "Purple|974|91"
record3 --> colorDimension : "Purple|974"
I need to facet on this colorDimension Field in a way such that term contains "Purple" and number "91".
The result I am targeting is -
Purple|91 = 2
I was looking out for facet.contains but did not get any examples that uses regular expressions.
You should expand these while indexing, so that you have a token for Purple|91 and Purple|974 separately. Faceting is quick because it can count tokens, without having to run a regex against each one to find the actual value.
You'll probably have to do this in your code, since I don't think you can make the pattern regex tokenizer spit out multiple tokens for a given prefix / group.
Try using this pattern:
Purple\|(?:\d+\|)*91(?:\||$)
Demo
If you actually need to make use of regular expressions, there is a parameter facet.matches, which can be used to specify a regular expression to restrict the facet results
I have a string "text text text 21.04.15 - 24.04.15 12345678".
I want to know if there is a date in this string that fits pattern xx.xx.xx - xx.xx.xx.
I understand xsl 1.0 doesnt support regex. How can i do this?
Thanks.
Try:
contains(translate($string,'123456789', '000000000'), '00.00.00')
Note that this may return false positives, for example if the string contains "123.45.3789". With some effort, you could eliminate these by including the surrounding punctuation (assuming you know all possible punctuation characters that could appear in the given text).
Note also that no testing is performed to make sure the pattern represents a a valid date.
XSL 1.0 is very old. Why can't you use XSL 2.0?
Using regular expressions:
\s+(\d{2}\.\d{2}\.\d{2})\s+\-\s+(\d{2}\.\d{2}\.\d{2})\s+
https://regex101.com/r/mW1sK2/2
Here's an article explaining XSL 2.0 regex from 2003:
http://www.xml.com/pub/a/2003/06/04/tr.html
I use a jmeter for REST testing.
I have made a HTTP Request, and this is the response data:
{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}
I need just the ID (which is 11) in
{"id":11,....
I use the REGEX below :
([0-9].+?)
It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :
([0-9][0-9].+?)
Is there any dynamic REGEX for my problem. Thank you for your attention.
Regards,
Stefio
If you want any integer between {"id": and , use the following Regular Expression:
{"id":(\d+),
However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.
I suggest using the following regular expression:
"id":([^,]*),
This will first find "id": and then look for anything that is not a comma until it finds a comma. Note the character grouping is only around the value of the ID.
This will work for ANY length ID.
Edit:
The same concept works for almost any JSON data, for example where the value is quoted:
"key":"([^"]*)"
That regular expression will extract the value from given key, as long as value is quoted and does not contain quotes. It first finds "key": and then matches anything that is not a quote until the next quote.
You can use the quantifier like this:
([0-9]{2,}.+?)
It will catch 2 or more digits, and then any symbol, 1 or more times. If you want to allow no other characters after the digits, use * instead of +:
([0-9]{2,}.*?)
Regex demo