Forum Discussion

daniegajohnson's avatar
daniegajohnson
Frequent Visitor
6 years ago
Solved

Keep text between // and /

I have this as my entry: Referrer: https://junebugweddings.com/wedding-blog/tropical-chic-garden-wedding-at-the-vanderbilt-museum/ I would like to keep just what's between // and the first /,...
  • v-lid-msft's avatar
    v-lid-msft
    6 years ago

    Hi  daniegajohnson ,

     

    We can create a custom column to meet your requirement:

     

    let d1 = Text.PositionOf([Referrer],"//"),
        d2 = Text.PositionOf(Text.End([Referrer],d1),"/")
    in
    Text.Range([Referrer],d1+2,if d2=-1 then Text.Length([Referrer])-d1-2 else d2)

     

     

    All the queries are here:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NY09EoIhDETvQm2g9yrMVwTIQBQI8qMeXwos3+y+XWsV1tCFA2Brd2O8FB1FYiZ9goOvxf45CLtPTr7qulmV5mxjO49Vya34oRC4xqH3hjkALks0s0tjjxl8Yg8Re6AK/wZOmIngve+oO84Tyhq0ilHX9QM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Referrer = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Referrer", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let d1 = Text.PositionOf([Referrer],"//"),
        d2 = Text.PositionOf(Text.End([Referrer],d1),"/")
    in
    Text.Range([Referrer],d1+2,if d2=-1 then Text.Length([Referrer])-d1-2 else d2))
    in
        #"Added Custom"

     


    Best regards,

     

  • Jimmy801's avatar
    Jimmy801
    6 years ago

    Hello daniegajohnson 

     

    then we can add 2 if-statements to check wheter the string is found or not

    let
        Quelle = "android-app://com.google.android.googlequicksearchbox",
        Pos1 = Text.PositionOf(Quelle, "//"),
        DeleteFirstPart = if Pos1 = -1 then Quelle else Text.End(Quelle,Text.Length(Quelle)-Pos1-2),
        Pos2 = Text.PositionOf(DeleteFirstPart,"/"),
        DeleteLastPart = if Pos2 = -1 then DeleteFirstPart else Text.Start(DeleteFirstPart,Pos2)
    in
        DeleteLastPart

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy