030
030

Reputation: 11679

Unable to match version using regex

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?

Upvotes: 1

Views: 179

Answers (2)

Ray Toal
Ray Toal

Reputation: 88378

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

Upvotes: 2

Severin
Severin

Reputation: 8588

Why don't you do it like this?

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

Upvotes: 1

Related Questions