Forum Discussion

GregBeaumont's avatar
GregBeaumont
Advocate II
9 years ago
Solved

A Simple Method to Filter Text Strings in Query Editor

Using M in Query Editor, I'm looking for a simple and efficient means by which to remove non-letters from a text column in a table. For example, if the first two rows within a column have values "this is not all_text!" and "1234Letters$" I'd like them to become "this is not all text" and "Letters". A few entries also have emojis that are pulled into the query, and I'd also like to scrub those out. Any suggestions are appreciated!

  • ImkeF's avatar
    ImkeF
    9 years ago

    No need to lowercase. Try this:

     

    Text.Remove(..YourText.., List.Transform({0..64, 91..96, 123..50000}, each Character.FromNumber(_))))

     

    This will remove every character within the range of 0..50000 that isn't a..z or A..Z. So if you have some special signs that you want to include, you need to find the number (Character.ToNumber) and include those numbers in the list above.

7 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    I'm not aware of a "non-letter"-class in M.

    Instead we have to define specificly a black- or whitelist: What shall stay in or what shall be removed?

    Which route would you prefer?

    • GregBeaumont's avatar
      GregBeaumont
      Advocate II

      I'm thinking I should set everything to lowercase, then create a whitelist for a-z. Probably the best way to eliminate odd characters. Thank you.

       

      Greg B

      • ImkeF's avatar
        ImkeF
        Community Champion

        No need to lowercase. Try this:

         

        Text.Remove(..YourText.., List.Transform({0..64, 91..96, 123..50000}, each Character.FromNumber(_))))

         

        This will remove every character within the range of 0..50000 that isn't a..z or A..Z. So if you have some special signs that you want to include, you need to find the number (Character.ToNumber) and include those numbers in the list above.