cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Syndicate_Admin
Administrator
Administrator

How to check that a specific text exists between two delimiters with M ?

Hello!

 

I'm looking to write a condition that checks that a text exists between two delimiters (without extraction). Exemple :

 

Data = aaa bbb ccc ddd eee rrr

 

How to check that "ccc" exists between "bbb" and "ddd"?

 

Thanks!

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Hi @cher90 ,
would that work for you?:

Text.BetweenDelimiters("aaa bbb ccc ddd eee rrr", "bbb ", " ddd") = "ccc"

Thanks ! it works fine when there are no values between "ccc" and "bbb" or "ddd"

 

How do I do the same for this case :

 

Data = aaa bbb xxx ccc ttt ddd eee rrr

 

How to verify that "ccc" exists between "bbb" and "ddd"

You could use Regular Expressions (and @ImkeF has a blog on using them), or you could split your string on the space, and check that the delimiters are present and in the correct order.

 

i.e:

    #"Added Custom" = Table.AddColumn(#"Previous Step", "Matches", each 
        let 
          split = Text.Split([Column with the strings to be tested]," "),
          params = {"bbb"} & {"ccc"} & {"ddd"},
          pos = List.Accumulate(params,{},(x,y)=> x & {List.PositionOf(split,y)})
        in 
          pos{0} < pos{1} and pos{1} < pos{2}, type logical)

Thanks a lot !

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,476)