DQL
Questions about Dynatrace Query Language
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using regex for a path

nisah
Visitor

Hi - 
I had the below regex working fine in a workflow
"| filter matchesRegex(lower(cicd.pipeline.url.full),".*/\\.github/workflows/.*(ci|standard).*\\.ya?ml$")"

Now i'm getting the below error for the same. Is there any way I can get it to work with other functions?
I have been trying with matchesPattern or matchesValue .. nothing is working

I'm trying to use regex to get the pattern as - .github/workflows/*ci*.yam*



"notifications": [
      {
        "message": "The function `matchesRegex()` is experimental and may be changed or removed at any time. Please change your query to use the function `matchesPattern()` instead.",
        "severity": "INFO",
        "arguments": [
          "matchesRegex",
          "matchesPattern"
        ],
        "messageFormat": "The function `%1$s()` is experimental and may be changed or removed at any time. Please change your query to use the function `%2$s()` instead.",
        "syntaxPosition": {
          "end": {
            "line": 30,
            "index": 1264,
            "column": 104
          },
          "start": {
            "line": 30,
            "index": 1170,
            "column": 10
          }
        },
        "notificationType": "DEPRECATED_FUNCTION_EXPERIMENTAL_USE_REPLACEMENT",
        "messageFormatSpecifierTypes": [
          "FUNCTION_NAME",
          "FUNCTION_NAME"
        ]

 

5 REPLIES 5

luisbsantos
Frequent Guest

Hi @nisah

there is a post that might bring some light to your question: https://community.dynatrace.com/t5/DQL/Regex-in-DQL/m-p/273446. The matchesRegex() function is being deprecated in favor of the matchesPattern() function, which allows standard wildcards (* and ?).

Did you try to add a new filter condition? Something like this:

| filter matchesPattern(lower(cicd.pipeline.url.full), "*/.github/workflows/*ci*.yam*")
   or matchesPattern(lower(cicd.pipeline.url.full), "*/.github/workflows/*standard*.yam*")

 

Hope it helps.

Thanks for the response.

I keep getting this error at the starting `*` of the string

"The parsing pattern is invalid. mismatched input '*' expecting {<EOF>, '>>', '!>>', '<<', '!<<', '<', VARIABLE_ID, CHARGROUP, INIT, STRUCTURE, ENUM, JSON, JSON_OBJECT, JSON_ARRAY, JSON_VALUE, ARRAY, DATA, LDATA, LD, KVP, GENERIC_ID, STRING_OPEN, NEWDOC_OPEN, '('}"

Hi @nisah,

Sorry. After checking that error message more carefully I realized I misled you, because the wildcard * doesn't work in DPL (Dynatrace Pattern Language), but in DQL (Dynatrace Query Language). In DPL the wildcard to represent "anything" (like what * does) is LD (Line Data), or DATA.

Since the function matchesPattern() uses DPL you need to use the LD in your command.

| filter matchesPattern(lower(cicd.pipeline.url.full), "LD '.github/workflows/' LD 'ci' LD '.yam' LD") 
 or matchesPattern(lower(cicd.pipeline.url.full), "LD '.github/workflows/' LD 'standard' LD '.yam' LD")

 

From my research, you can also use the function matchesValue() which actually supports the * wildcard. If you use this approach instead, I suggest using it with the partial match. Maybe something like this:

| filter matchesValue(lower(cicd.pipeline.url.full), ["*.github/workflows/*ci*.yam*", "*.github/workflows/*standard*.yam*"], partialMatch:true)

 

@luisbsantos Thank you for your response. Yea I was working few method and found out LD is like * in regex. I used below regex and it worked. 

// | filter matchesPattern(cicd.pipeline.url.full, "LD? 'github/workflows/' LD? 'ci' LD?")

 

Below solution still throws error 

| filter matchesValue(lower(cicd.pipeline.url.full), ["*.github/workflows/*ci*.yam*", "*.github/workflows/*standard*.yam*"], partialMatch:true)

A string like "*.github/workflows/*ci*.yam*" isn't allowed here. Please check the autocomplete suggestions before the error for alternative options.

Thank you so much for solutions 🙂

 

For simple patterns you may also consider using like() funtion (https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/string-functions#l...) acting like LIKE operator in SQL

Featured Posts