简体   繁体   English

在Javascript中获取两个字符串之间的字符串

[英]Get a string between two strings in Javascript

I have the below string that I need help pulling an ID from in Presto.我有以下字符串,需要帮助从 Presto 中提取 ID。 Presto uses the javascript regex. Presto 使用 javascript 正则表达式。 I've searched multiple options including:我搜索了多个选项,包括:

JavaScript text between double quotes 双引号之间的 JavaScript 文本

Javascript regex to extract all characters between quotation marks following a specific word Javascript正则表达式提取特定单词后面引号之间的所有字符

I need to pull the GA Client ID which looks like this: 75714ae471df63202106404675dasd800097erer1849995367我需要提取如下所示的 GA 客户端 ID: 75714ae471df63202106404675dasd800097erer1849995367

Below is a snipped where it sits in the string.下面是它在字符串中的一个片段。

The struggle is that the "s:38:" is not constant.斗争是“s:38:”不是恒定的。 The number can be anything.数字可以是任何东西。 For example, it could be s:40: or s:1000: etc. I need it to return just the alphanumeric id.例如,它可能是 s:40: 或 s:1000: 等。我需要它只返回字母数字 ID。

String Snippet字符串片段

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

Full string listed below下面列出了完整的字符串

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";} ```


This works for your sample这适用于您的样品

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM