1

Introduction

Aim: to match version (2.4.0) located in sample using ketarin

Regular expression:

(?=.*Release.*)[\d\.]+(?=.*available)

Other digits are matcht as well according Rubular.

<a href="#News">News</a>
<ul class="minitoc">
<li>
<a href="#07+April%2C+2014%3A+Release+2.4.0+available">07 April, 2014: Release 2.4.0 available </a>
</li>
<li>
<a href="#20+February%2C+2014%3A+Release+2.3.0+available">20 February, 2014: Release 2.3.0 available </a>
</li>

Question

How to match the version (2.4.0) from this text using regex?

2 Answers 2

2

You were close; the first part should have been a lookbehind, not a lookahead.

/(?<=Release )[\d.]+(?= available)/

worked for me: http://rubular.com/r/VuYVl9xMum

Change the spaces to your needs. Also note that the regex allows things like 34.....3.1..... so consider

\d+(\.\d+)*

for version numbering.

UPDATE: A new version, using this version number pattern, at http://rubular.com/r/H4hIDKZz2V

Sign up to request clarification or add additional context in comments.

1 Comment

This works in Rubular while this is not the case in ketarin. Thank you.
1

Why don't you do it like this?

/Release\+(\d\.\d\.\d)\+available/

3 Comments

According to Rubular this results in Release+2.4.0+available, while this regex works in ketarin. Thank you.
But it's got a capture group which matches 2.4.0 only. I can't tell you exactly how to get the string from the capture group, because you haven't told us which language you're using, but there should be some way of doing it, and it's the more common way than using lookarounds. My only objection to Severin's answer is that it doesn't match strings such as Release+2.10.0+available (where one of the numbers has two digits) but you can easily fix this by replacing \d with \d+.
@DavidKnipe A combination of Severin's and RayToal's answer: Release\+([\d.]+)\+available works in ketarin. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.