Skip to main content
tejashwinin0822
March 15, 2023
Question

Extract Function

  • March 15, 2023
  • 22 replies
  • 0 views

Hi All I have requirement to get the values between  square brackets iam achieving it with the help of  extract function but when i was trying to insert the brackets after entering value and if my text value has uneven number of brackets it is erroring out

 

can you suggest is their any other alternate way to achieve this 

    22 replies

    stewart.burchell
    March 15, 2023

    I would encourage you to validate the incoming string before you attempt to use the extract() function on it. There are probably a few ways to do this but in essence if you check that the string you want to process contains an even number of "[" and "]" characters then you'll avoid the error. What might be a bit harder to achieve is to ensure that every "[" has a following "]" without another intervening "["...if that even matters to you? But the principle here: don't attempt to process data that is effectively invalid.

    stewart.burchell
    March 15, 2023

    ...of course if you treat "[" and "]" as just pure delimiters then you can do something like this, which isn't sensitive to the need for each "[" to have a matching "]"

    fn!reject(
      a!isNullOrEmpty,
      a!flatten(
        a!forEach(
          items: split(ri!myString, "["),
          expression: split(fv!item, "]")
        )
      )
    )

    tejashwinin0822
    March 15, 2023

    will definetly try this Thank you for the quick response 

    abhayd3663
    March 15, 2023
    mikes0011
    Brainy
    March 15, 2023

    not sure what the point of this is - this doesn't have much to do with the error the user describes.

    The Expression Guru
    abhayd3663
    March 15, 2023

    May be it make sense to the other person on how the exact() function works, because the the original post and subject  mentions about extract() function.

    shanmathip7466
    Inspiring
    July 11, 2023

    Hi [mention:e38c17c52b794f95af87209b055e7b04:e9ed411860ed4f2ba0265705b8793d05],

    Can you please check if the below code works for your use case?

    a!localVariables(
      local!values: split(ri!myString, "["),
      local!valuesWithCloseBracket: reject(
        a!isNullOrEmpty,
        a!forEach(
          items: local!values,
          expression: if(search("]", fv!item) > 1, fv!item, null)
        )
      ),
      a!forEach(
        items: local!valuesWithCloseBracket,
        expression: split(fv!item, "]")[1]
      )
    )