I have a string as <tr><td>Version:</td><td>6.3.13.2</td></tr> I want to extract 6.3.13.2 from this. How can I do so in Groovy regex, please help.
For the example presented, you can use:
/[\d.]+/
Regex Demo and Explanation
For the example provided you could use a simple regular expressions like this
/[\d.]+/
It would be better if you use
(?:<td>)([\d.]+)(?:<\/td>)
and take this capture group and replace it what you want.
Learn about regular expressions here
REGEX Library, tester, documentation, cheat sheet
Related
What is a correct regex for matching semantic versioning?
It should not match for instance
01.1.1
9.8.7-whatever+meta+meta
1.2.3.DEV
1.2.3-0123
1.0.0-alpha_beta
1.2-SNAPSHOT
1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788
it should match for instance
0.0.4
1.2.3
10.20.30
1.1.2-prerelease+meta
1.1.2+meta
1.0.0-alpha
1.0.0-alpha.beta
1.0.0-alpha.1
1.0.0-alpha.0valid
1.0.0-rc.1+build.1
1.2.3-beta
10.2.3-DEV-SNAPSHOT
1.2.3-SNAPSHOT-123
1.0.0
2.0.0+build.1848
2.0.1-alpha.1227
1.0.0-alpha+beta
1.2.3----RC-SNAPSHOT.12.9.1--.12+788
1.2.3----R-S.12.9.1--.12+meta
Take a look on the bottom of the SemVer page:
Is there a suggested regular expression (RegEx) to check a SemVer string?
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
A working regex would be
^(0|[1-9]+[0-9]*)\.(0|[1-9]+[0-9]*)\.(0|[1-9]+[0-9]*)(-(0|[1-9A-Za-z-][0-9A-Za-z-]*)(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$
Working against every flavor available at regex101.com
This is a somewhat simpler version missing the capture groups from the »official« one if you don’t need those and want to keep it simple.
I'm new in regex and I have a question.
Like in this example, https://regex101.com/r/Iak7cF/1/ how do I force
src="wow"
to be in group 1, and
title="toto"
to be in group 2?
I want to capture this kind of text in any order only if it contains:
class="formula"
Am I doing it right?
You'd better use an HTML parser
But if you really want to use regex, you have to use named groups to achieve what you want.
<img(?=[^>]*class="formula")(?=.*(?<src>src=".*"))(?=.*(?<title>title=".*")).*>
DEMO
Regular expressions are very flexible and powerful, but in general, they are not the right tool for parsing XML, HTML, or XHTML. From WinBatch:
Regular Expressions are only good for parsing text that is tightly defined. Since Regular Expressions don't really understand the context of matches, they can be fooled in a big way if the structure of the text changes. In particular, Regular Expressions have difficulty with hierarchy.
PerlMonks has a detailed explanation of why regex is not a good solution for all but the most simple of casess. They summarize it like this:
So I hope it is clear: Please, don't try to parse arbitrary XML/HTML with regexes!
This is the issue I face
The String
nt/sign-in?wa=wsignin1.0&wtre
The Need
From that string I need to extract the following
wsignin1.0
The Attempts
So far I have tried the following Regex
wa=(.*?)(?=&)
This returns:
wa=wsignin1.0
The "wa=" is not supposed to be there
Perhaps with a look behind?
(?<=wa\=)(.+)(?=\&wtre)
wsignin1.0
JMeter uses Perl5-style regular expressions therefore the regex you are looking for might be as simple as:
wa=(.+?)&wtre
Demo:
Use $1$ as "Template" in your Regular Expresssion Extractor.
See How to Debug your Apache JMeter Script for more details on JMeter tests troubleshooting.
=([\w.]++)
will capture it in the first capture group. Otherwise I think #jivan has a good idea with the lookbehind. A little tweak too it:
(?<==)[\w.]++
Put this in your Regular Expression extractor:
nt/sign-in?wa=([a-zA-Z0-9\.]*)&wtre
I hope this help you.
I am trying to replace
<legend>my legend</legend>
with
<legend><span>my legend</span></legend>
Intellij/Webstorm,supports regexp match and replace.
I tried along the examples here, but didn't work.
Any help on a regexp to find and replace as described above is appreciated.
I use mac, so gnu command line tools also an option (sed,..)
Thanks.
Use replace with the following regular expression:
<legend>([^<]*)</legend>
and replacement
<legend><span>$1</span></legend>
I have a big list with links and other date in it. I want to filter out all the data and have a list with just the links.
Example of the current list:
32,2012-01-04 06:44:44,http://link.com/link
33,2012-01-04 06:44:45,http://link.com/link,{Text|textext|text},http://link.com/link|http://link.com/link|http://link.com/link
Notepad++ offers find replace functionality using RegEx. You can access this feature by using Ctrl+H.
If you're actually asking for a regular expression to do this, you can use something like this to match URLs:
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
which I found here.
Additionally you can test out changes to your regex easily at http://gskinner.com/RegExr/
Using the input you provided, here's a pattern you can use on http://www.regexr.com/
You'll need to make sure the global (/g) flag is on
Expression:
.*?(http.*?)[,|\n]
Input:
32,2012-01-04 06:44:44,http://link.com/link1
33,2012-01-04 06:44:45,http://link.com/link2,{Text|textext|text},http://link.com/link3|http://link.com/link4|http://link.com/link5
Substitution:
$1\n
Output:
http://link.com/link1
http://link.com/link2
http://link.com/link3
http://link.com/link4
http://link.com/link5