Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex plug-in only returns one matched value after regular expression matches. #85

Open
pangteckchun opened this issue Apr 26, 2024 · 2 comments
Labels
feature Some functionality to be developed low-priority low priority issue

Comments

@pangteckchun
Copy link

Description of the Error

While using regex plug-in to extract part of instance type parameter value, only a single matched value is returned from matches.

Expected Behaviour

Given this input string "Standard_DS2_v1" and the regular expression "/(?<=)[^_]+?(?=|$)/g", I wanted it to return "DS2 v1" of the 2 matched elements with a space in between.

Actual Behaviour

The return result is only "DS2" , first matched element but without the second matched element "v1" in the total result.

Steps to Reproduce

Run regex plug-in using IF manifest (output section shown below):

name: regex-demo
description: null
tags: null
initialize:
  plugins:
    regex:
      path: '@grnsft/if-plugins'
      method: Regex
      global-config:
        parameter: cloud/instance-type
        match: /(?<=_)[^_]+?(?=_|$)/g
        output: cloud/instance-type
  outputs:
    - yaml
if-version: v0.3.1
tree:
  children:
    child:
      pipeline:
        - regex
      config:
        regex: null
      inputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          cloud/instance-type: Standard_DS1_v2
      outputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          cloud/instance-type: DS1

Link to online environment

Used https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#try_it to try out the same string and regex inputs, since the plug-in typescript leverages the standard String prototype match() method.

const paragraph = 'Standard_DS1_v2';
const regex = /(?<=_)[^_]+?(?=_|$)/g;
const found = paragraph.match(regex);

console.log(found);
console.log(found[0]);
// Produces output: Array ["DS1", "v2"]
// And "DS1"

Looking at https://github.com/Green-Software-Foundation/if-plugins/blob/main/src/lib/regex/index.ts, it returns only the 1st array object in extractMatching block, which is incorrect.

Additional qns: if the entire array is returned, how can we concatenate the elements together or can regex do that for us, with space between the elements?

Manifest File That Generated the Error

name: regex-demo
description: null
tags: null
initialize:
  plugins:
    regex:
      path: '@grnsft/if-plugins'
      method: Regex
      global-config:
        parameter: cloud/instance-type
        match: /(?<=_)[^_]+?(?=_|$)/g
        output: cloud/instance-type
  outputs:
    - yaml
if-version: v0.3.1
tree:
  children:
    child:
      pipeline:
        - regex
      config:
        regex: null
      inputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          cloud/instance-type: Standard_DS1_v2

Links to Any Additional Code

NA

Runtime Info

Running on local laptop: Windows OS 10
IF version:

+-- @grnsft/if-plugins@v0.3.0
+-- @grnsft/if-unofficial-plugins@v0.3.1
`-- @grnsft/if@v0.3.1
@jmcook1186 jmcook1186 added bug Something isn't working feature Some functionality to be developed labels Apr 26, 2024
@zanete zanete added low-priority low priority issue and removed bug Something isn't working labels Apr 30, 2024
@jmcook1186
Copy link
Contributor

jmcook1186 commented Apr 30, 2024

Hi @pangteckchun - sorry this isn't working for you. It's not really a bug as the plugin is only intended to give the first match. Appreciate you need multiple matches - so what we'll do is close this bug report and open a feature request instead and build out the multiple match functionality in the coming sprints.

Tagging myself @jmcook1186 as a reminder to make the dev ticket!

@pangteckchun
Copy link
Author

Thank you James for following up! Appreciate this.
Noted the original feature is to only return the 1st match. For now I will workaround using my own CLI program integrating it to the my pipeline using shell plug-in.

Looking forward to its future evolution.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Some functionality to be developed low-priority low priority issue
Projects
Status: Parked
Development

No branches or pull requests

3 participants