Platform

Platform

A place for Apptio product users to learn, connect, share and grow together.

Β View Only
  • 1.  What does this Regex formula do

    Posted Tue June 13, 2023 05:38 PM
    Can anyone tell me what this formula is doing?
    =ReplaceRegex(Journal Line Description,"\W+"," ")


    ------------------------------
    KristineKleinTerex CorporationSenior Operations Specialist TBMA
    ------------------------------

    #TBMStudio


  • 2.  RE: What does this Regex formula do

    Posted Tue June 13, 2023 05:50 PM
    Edited by Dan Kelly Tue November 05, 2024 06:11 PM

    "\W" matches any non-word character (so anything other than [^a-zA-Z0-9_]).  The "+" means one or more of the item.

    So that statement is removing all non-word characters in the Journal Line Description.

    Also, if you aren't familiar with regular expressions there is also "\w" (with a lower case "w") which matches only word characters.




  • 3.  RE: What does this Regex formula do

    Posted Tue June 13, 2023 05:54 PM

    Thanks. I understand now. what does this mean  [^a-zA-Z0-9_])



    ------------------------------
    KristineKleinTerex CorporationSenior Operations Specialist TBMA
    ------------------------------



  • 4.  RE: What does this Regex formula do

    Posted Tue June 13, 2023 06:08 PM

    Sorry, I should have been clearer.  I edited my original post, but I will also elaborate here.

    So word characters, which are matched by "\w" (lower case "w") are in the set [^a-zA-Z0-9_].  Where the set is bounded by "[^" and "]".  Or in plain English: lower case or upper case letters, the digits zero through nine, and the underscore character.  The reason an underscore is part of the set of word characters is for cryptic historical reasons.

    "\W" (capital "W") is non-word characters.  So everything else like hyphens, "special characters" (e.g. !@#$% etc.).




  • 5.  RE: What does this Regex formula do

    Posted Wed June 14, 2023 12:55 PM

    Thank you so much that makes a lot of sense. I tried to google that but it doesn't work very well when you google [^a-zA-Z0-9_])



    ------------------------------
    KristineKleinTerex CorporationSenior Operations Specialist TBMA
    ------------------------------



  • 6.  RE: What does this Regex formula do

    Posted Wed June 14, 2023 04:03 PM
    Edited by System Admin Tue November 05, 2024 05:51 PM

    "\W+" will match one or more consecutive non-word characters. It can be used to identify and split text based on non-alphanumeric characters, such as spaces, punctuation marks, and special symbols.

    So, for example, suppose you have a string for IT Tower-SubTower like "Compute-Servers". If you wanted to split the string, you'll need a regular expression that will identify the special character or delimiter. "\W+" (without the quotes) will select the "-". If you made it "Compute - Servers", it will select the spaces as well, so " - ". If you have users that sometimes use a dash, sometimes an underscore, and sometimes a pipe symbol (|), all with or without spaces with no rhyme or reason, it will select all of those as well without having to make changes to the formula. 

    Go to the regex 101 website and you can test all these cases out.

    For the expression itself, the "\" is an escape that means the next character has special meaning - otherwise the expression would just look for a "W". As mentioned, "\W" means "find a non-word character." Adding the plus sign "\W+" means "match one or more characters," which is why it will expand the results from "-" to " - " with no changes.

    I used to struggle to build these. Now I just ask ChatGPT to write them and life is good. Especially for regex for Apptio, which sometimes doesn't process the way I expect. In that case, I give ChatGPT the failed results I get back, and it makes recommendations on how to fix to get the right match and return the right group. Hope this helps!




  • 7.  RE: What does this Regex formula do

    Posted Thu June 15, 2023 12:09 PM

    Haha, I use ChatGPT all the time as well - love it! 😎




  • 8.  RE: What does this Regex formula do

    Posted Fri June 16, 2023 02:26 AM

    My knowledge of regular expressions is rudimentary, to say the list. But it's good to know that good ol' ChatGPT knows its ways around them πŸ‘πŸ‘πŸ‘



    ------------------------------
    Regards, Guillermo
    ------------------------------