Home > OS >  How can I extract a major and minor version number from the end of a string?
How can I extract a major and minor version number from the end of a string?

Time:01-22

I'm trying to extract the CMS Tikiwiki version, but I have a problem extracting the version. I'm able to extract only the first part of the number, example:

Version 15.0, I can extract only 15, but I want to extract 15.0.

if ($res=~ m/as of version (. ?)\./) {

  $version = $1;

 }

Sentences to extract version

The following list attempts to gather the copyright holders for Tiki as of version 15.0.

CodePudding user response:

Try this,

if ($res =~ m/as of version (\d (?:\.\d ))\./) {

If this is the end of the string you may want,

if ($res =~ m/as of version (\d (?:\.\d ))\.$/) {

The pattern (\d (?:\.\d )) captures any digit followed by an optional grouping of . and one or more digits.

CodePudding user response:

You can use

/as of version (. )\./

but I would be tempted to use

/as of version (\S )\./

\S matches non-space characters.


By the way,

my $version
if ( $res =~ /.../ ) {
   $version = $1;
}

can be written as

my ( $version ) = $res =~ /.../;
  •  Tags:  
  • Related