【问题标题】:regex extract in google data studio谷歌数据工作室中的正则表达式提取
【发布时间】:2021-10-27 13:15:54
【问题描述】:

我正在尝试从页面谷歌分析维度中提取值(在本例中为 max 和 min price ),但遇到了一个问题,因为 max/min price 的位置可能因用户进行的搜索而异。

我试过了:REGEXP_EXTRACT(Page,'.*minPrice.=(.*)')

当值位于字符串末尾时它工作正常,但当值位于开头或中间时捕获字符串的其余部分。

以下是页面值的示例:

/search/detail/119441465?s[propertyTypes][0]=house&spropertyTypes=condo&s[minPrice]=999999&s[locations][0][city]=Ocean City&s[locations][0][state] =新泽西州

/search?s[propertyTypes][0]=house&spropertyTypes=condo&s[minPrice]=999000&s[orderBy][0]=r&s[locations][0][city]=Barnegat Light&s[locations][0 ][州]=新泽西州

/search/detail/118588431?s[propertyTypes][0]=house&spropertyTypes=condo&s[minPrice]=999000&s[locations][0][city]=Barnegat Light&s[locations][0][state] =新泽西州

/search/detail/118588431?s[city]=Barnegat Light&s[state]=NJ&s[propertyTypes][0]=house&spropertyTypes=condo&s[minPrice]=999000

/search/detail/119438690?s[orderBy]=sourceCreationDate,desc&s[locations][0][city]=Venice&s[locations][0][state]=FL&s[maxPrice]=525000&s[minPrice]=99900

/search?s[orderBy]=sourceCreationDate,desc&s[locations][0][city]=Venice&s[locations][0][state]=FL&s[maxPrice]=525000&s[minPrice]=99900

/search/detail/119337213?s[orderBy]=sourceCreationDate,desc&s[locations][0][state]=NJ&s[locations][0][county]=蒙茅斯县&s[maxPrice]=1488000&s[minPrice]= 992000

/search/detail/119415983?s[orderBy]=sourceCreationDate,desc&s[locations][0][state]=NJ&s[locations][0][county]=蒙茅斯县&s[maxPrice]=1488000&s[minPrice]= 992000

/search/detail/119046654?s[orderBy]=sourceCreationDate,desc&s[locations][0][state]=NJ&s[locations][0][county]=格洛斯特县&s[maxPrice]=148800&s[minPrice]= 99200

/search?s[orderBy]=sourceCreationDate,desc&s[locations][0][state]=NJ&s[locations][0][county]=格洛斯特县&s[maxPrice]=148800&s[minPrice]=99200

/search/detail/119330920?s[orderBy]=sourceCreationDate,desc&s[locations][0][state]=NJ&s[locations][0][county]=格洛斯特县&s[maxPrice]=148800&s[minPrice]= 99200

【问题讨论】:

    标签: regex google-data-studio


    【解决方案1】:

    你可以使用

    REGEXP_EXTRACT(Page,'[[]minPrice[]]=([0-9]+)')
    REGEXP_EXTRACT(Page,r'\[minPrice]=(\d+)')
    

    请参阅regex demo详情

    • [[]minPrice[]]= / \[minPrice]= - [minPrice]= 字符串
    • ([0-9]+) / \d+ - 第 1 组:一位或多位数字。

    .* 不是必需的,因为REGEXP_EXTRACT 不会将匹配项锚定在字符串的开头。

    【讨论】:

    • 完成。如果不是问题,还有一个问题。如何在位置 0 下取值:[locations][0][city]=VALUE&s
    • @user3191724 我想应该是r'\[locations]\[0]\[city]=([^&?#]+)',见the regex demo
    • 非常感谢你,维克托!
    • 还有一个问题。当 [propertyTypes] 可以有 [0] 或 [] 时,我正在尝试提取属性类型:/search/detail/119441465?s[propertyTypes][0]=house&spropertyTypes=condo&s[minPrice]=999999&s[locations][0] [city]=海洋城&s[locations][0][state]=NJ /search?s[locations][0][city]=Newark&s[locations][0][state]=NJ&s[propertyTypes][]=house&pvl =1&lvl=1&hvl=1&photoCountMin=1&r=1&noEdit=1&limit=8
    • @user3191724 要匹配可选的0 字符,请使用0?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 2019-02-14
    • 2020-01-19
    • 2016-04-26
    • 2013-01-30
    相关资源
    最近更新 更多