Forum Discussion

pranil2k2's avatar
pranil2k2
Contributor
6 years ago

How to Split using Regex expression

Hi,

I need some help on spliting the user name on basis of Regex expression.My user Name is an combination of mutliple users and i cant use comma to split them. so, i tried regular expression and which is working good on DB level and planned to implement same in Snaplogic, but it is not working. Please some one can help me here.

8 Replies

  • Are you able to share an example name, or confirm if something like JohnBobSarahBill is a good example? If so, and if this could be any combination of names, what are you able to split on? Is each name always the same length?

  • Hi,

    The best example is below, it have three names separated by comma, so I thought of using some logic as
    “regexp_substr(dossier_lead, ‘[[:alnum:] .()-]+, [[:alnum:] .()-]+’,1, level,‘i’)” it is working in oracle but it is hanging, so i thought of trying same logic in snaplogic.

    Example: john, maria,lisa, awari,Arun, john(TCS)

    • RogerSramkoski's avatar
      RogerSramkoski
      Employee

      Thank you for the additional information. I believe there was a typo in the initial post indicating that you could not use commas. If your JSON was something like “names” : “john, maria,lisa, awari,Arun, john(TCS)” you could use the expression $names.split(‘,’) which will result in a “names” array. If you want to remove the white space you could use $names.replaceAll(’ ‘,’‘).split(’,').

      Screenshot of split only:

      Screenshot of expression with replaceAll and split:

      • pranil2k2's avatar
        pranil2k2
        Contributor

        Hi,
        I tried above solution, but i am getting output as below

        .

        but the excepted output will be combination of first name and last name (john, maria).

        Any advice. Thanks

  • Hi,
    so by doing above can I except the result will be like three rows as below?
    john, maria
    lisa, awari
    Arun, john(TCS)

  • The names are combination of first name and last name saperated by comma. so the output will be like
    john, maria (first name, last name)