【问题标题】:Get a string between two strings in Javascript在Javascript中获取两个字符串之间的字符串
【发布时间】:2020-01-09 13:05:11
【问题描述】:

我有以下字符串,我需要帮助从 Presto 中提取 ID。 Presto 使用 javascript 正则表达式。我搜索了多个选项,包括:

JavaScript text between double quotes

Javascript regex to extract all characters between quotation marks following a specific word

我需要提取如下所示的 GA 客户端 ID: 75714ae471df63202106404675dasd800097erer1849995367

下面是一个片段,它位于字符串中。

问题在于“s:38:”不是恒定的。数字可以是任何东西。例如,它可以是 s:40: 或 s:1000: 等。我需要它只返回字母数字 id。

字符串片段

"GA_ClientID__c";s:38:"75714ae471df63202106404675dasd800097erer1849995367";

下面列出的完整字符串

99524";s:9:"FirstName";s:2:"John";s:8:"LastName";s:8:"Doe";s:7:"Company";s:10:"Sample";s:5:"Email";s:20:"xxxxx@gmail.com";s:5:"Phone";s:10:"8888888888";s:7:"Country";s:13:"United States";s:5:"Title";s:8:"Creative";s:5:"State";s:2:"NC";s:13:"Last_Asset__c";s:40:"White Paper: Be a More Strategic Partner";s:16:"Last_Campaign__c";s:18:"70160000000q6TgAAI";s:16:"Referring_URL__c";s:8:"[direct]";s:19:"leadPriorityMarketo";s:2:"P2";s:18:"ProductInterest__c";s:9:"sample";s:14:"landingpageurl";s:359:"https://www.sample.com;mkt_tok=samplesamplesamplesample";s:14:"GA_ClientID__c";s:38:"75714ae471df63202106404675dasd800097erer1849995367";s:13:"Drupal_SID__c";s:36:"e1380c07-0258-47de-aaf8-82d4d8061e1a";s:4:"form";s:4:"1046";} ```


【问题讨论】:

标签: javascript regex presto


【解决方案1】:

这适用于您的示例

"GA_ClientID__c";[^"]*"([^"]*)"

https://regex101.com/r/Q4Orj6/1

【讨论】:

  • 从下面的GA_ClientID开始的整个字符串中拉下:“GA_CLIENTID__C”; S:38:“GA_CLIENTID__C”; S:38:“GA_CLIENTID__C”; S:38:38:38:38:38:38:38:38:38:38:38:3):38:38:38 "45334344195681961193291818769152505335" "GA_ClientID__c";s:38:"42976399188084801382077697423679114357"
  • 我可以看到它在测试器中工作,但是当我运行它时,它仍然返回完整的字符串。这是 Presto 的正则表达式实现的文档:prestodb.github.io/docs/current/functions/regexp.html 让我看看我是否能弄清楚他们改变了什么
  • @cauthon - Presto -> All of the regular expression functions use the Java pattern syntax -> "\"GA_ClientID__c\";[^\"]*\"([^\"]*)\"" ?
  • 你的答案是正确的。我错过了 SQL 中的组标志。 regexp_extract(a.attributes_value, 'GA_ClientID__c\";[^\"]*\"([^\"]*)',1) 谢谢!!!
  • @cauthon - 尽管它可能以这种方式工作GA_ClientID__c";[^"]*"([^"]*),但最好保留开头和结尾的闭包"\"GA_ClientID__c\";[^\"]*\"([^\"]*)\""'\"GA_ClientID__c\";[^\"]*\"([^\"]*)\"'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-02
  • 2012-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多