Skip to main content
added 1 characters in body
Source Link
Explosion Pills
  • 192.4k
  • 56
  • 341
  • 417

I have a string which has below value

"String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64"

String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64

I need to extract only version from this string which is "1.2.0-4"

I have tried regular expression as mentioned below with sed

"sed -ne 's/[^0-9](([0-9].){0,1}[0-9][^.])./\1/p' "

sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,1\}[0-9][^.]\).*/\1/p'

but I am only getting result "1.2.0-", missing number after "-" which is 4. I tried correcting it but it is returning null.

Kindly, advise

I have a string which has below value

"String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64"

I need to extract only version from this string which is "1.2.0-4"

I have tried regular expression as mentioned below with sed

"sed -ne 's/[^0-9](([0-9].){0,1}[0-9][^.])./\1/p' "

but I am only getting result "1.2.0-", missing number after "-" which is 4. I tried correcting it but it is returning null.

Kindly, advise

I have a string which has below value

String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64

I need to extract only version from this string which is "1.2.0-4"

I have tried regular expression as mentioned below with sed

sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,1\}[0-9][^.]\).*/\1/p'

but I am only getting result "1.2.0-", missing number after "-" which is 4. I tried correcting it but it is returning null.

Kindly, advise

Source Link

Regex to extract version from string

I have a string which has below value

"String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64"

I need to extract only version from this string which is "1.2.0-4"

I have tried regular expression as mentioned below with sed

"sed -ne 's/[^0-9](([0-9].){0,1}[0-9][^.])./\1/p' "

but I am only getting result "1.2.0-", missing number after "-" which is 4. I tried correcting it but it is returning null.

Kindly, advise