1

I am trying to extract last entry from an curl output to only show me the plugin-name and version. Unfortunately miserably failing with my command. Here is the command being used at my end

curl --silent https://jenkins-updates.cloudbees.com/download/plugins/blueocean-github-pipeline/ --ssl-no-revoke | findstr href |Select-String -Pattern "[0-9]/([^<]*)<" |Select-Object -last 1 | ForEach-Object { $_.Matches[0].Groups[1].Value }

Output its giving is blueocean-github-pipeline.hpi">1.25.3

I wish to display only the following blueocean-github-pipeline 1.25.3

and remove "> with a tab in between

How should I go about it?

Thanks in advance

Rohit
  • 245
  • 1
  • 2
  • 6

1 Answers1

0

You can use

... | Select-String -Pattern '\d/([^>]*)\.\w+">([^<]*)<' | `
Select-Object -last 1 | `
ForEach-Object { $_.Matches[0].Groups[1].Value + " " + $_.Matches[0].Groups[2].Value }

Output:

blueocean-github-pipeline 1.25.2

See the regex demo.

Details:

  • \d/ - a digit and a / char
  • ([^>]*) - Group 1: any zero or more chars other than a > char
  • \. - a dot
  • \w+ - one or more word chars
  • "> - a fixed string
  • ([^<]*) - Group 2: any zero or more chars other than a < char
  • < - a < char.

The final result is the concatenation of Group 1 + space + Group 2.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Thanks exactly what I was hoping for :-) – Rohit May 11 '22 at 14:40
  • @Rohit You are welcome. This is a common solution when you need to handle disjoint pieces of text to capture them into two groups and later concatenate. There is a way to do it with a replacing approach, but in this case, it is more convenient to use capturing/concatenation. – Wiktor Stribiżew May 11 '22 at 14:41