Zoker
Zoker

Reputation: 2059

Filter a version number out of a string

I want to filter a number out of a string with php preg_match that could look like this (they are versions of a software):

(1.6.2#2 is 2. beta of 1.6.2)

So when there is a string like:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, 1.6.2# sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

Now I want a string that only contains "1.6.2#2"

I tried (\d?[.|#]?)* but it does not work

Upvotes: 1

Views: 81

Answers (1)

Yasen Zhelev
Yasen Zhelev

Reputation: 4045

Use this regular expression

/(\d+\.\d+(\.\d+)?(#\d+)?)/

Upvotes: 2

Related Questions