regex for semver - regex

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.

Related

How to extract the version info using regex in Groovy

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

Regex: Extract string between two strings

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=(.*?)(?=&amp)
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.

Regular expression not working in google analytics

Im trying to build a regular expression to capture URLs which contain a certain parameter 7136D38A-AA70-434E-A705-0F5C6D072A3B
Ive set up a simple regex to capture a URL with anything before and anything after this parameter (just just all URLs which contain this parameter). Ive tested this on an online checker: http://scriptular.com/ and seems to work fine. However google analytics is saying this is invalid when i try to use it. Any idea what is causing this?
Url will be in the format
/home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd
so i just want to capture URLs that contain that specific "z" parameter.
regex
^.+(?=7136D38A-AA70-434E-A705-0F5C6D072A3B).+$
You just need
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B.+$
Or (a bit safer):
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&.+$)
And I think you can even use
=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&)
See demo
Your regex is invalid because GA regex flavor does not support look-arounds (and you have a (?=...) positive look-ahead in yours).
Here is a good GA regex cheatsheet.
To match /home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd you can use:
\S*7136D38A-AA70-434E-A705-0F5C6D072A3B\S*

Regular Expression is working for php not for JavaScript

This is my expression:
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])[[:graph:]]{6,25}$
I have tested it on http://regex101.com/
Its working for string DeepakManwal1 when there is php selected but does not work when javascript is selected. I don't know what is the exact reason.
I want to use this expression for password validation where there should be at-least one uppercase letter and one numeric character.
Here is fiddle http://jsfiddle.net/j7rmj44h/
It is because of the POSIX class [:graph:] — you could change it to the equivalent [\x21-\x7E]. Also, you need to remove the quotations around your pattern according to your fiddle.
var re = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])[\x21-\x7E]{6,25}$/
Fiddle
AFAIK, javascript doesn't understand POSIX.
Have a try with:
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])\S{6,25}$
Different regex engines have different capabilities. Only the simplest of regex can be shared across implementations.
If I recall correctly [:graph:] like specification of character classes is not supported in JS.

Specific word followed by full stop followed by another group RegEx

Hi I'm having a little trouble with a regular expression.
I tested:
([Version]+)\.([.0-9A-Za-z]+)
With:
/Downloads/Documents/Access MDB - DEV Version.2.1.4.zip
This worked in RegexHero, my groups seemed fine (sort of).
However when I'm searching through HTML source code it returns things like:
e.axd
How would I get 2 groups:
Version.
2.1.4.zip
Or even one group?
Version.2.1.4.zip
I'm puzzling over this, regular expressions aren't my strong suit.
Version.2.1.4.zip in one group,
^.* (.*)$
DEMO
After using Avinash's answer as a baseline I found the solution as:
(version.*\.zip)
This matches what I needed
version.2.1.4.zip