简体   繁体   English

两个词之间的正则表达式

[英]Regular Expression between two words

I will really appreciate your help. 非常感谢您的帮助。 What happens is that my code gets a string vía ajax from a php file. 发生的是我的代码从php文件中获取了字符串víaajax。 The php file returns a long string that contains the following "css":["DSK\\/y"],"js":["V5Llk","1dVnw"],"onload":["goURI(\\"\\\\\\/procedure\\\\\\/376993639056176\\\\\\/?context=create\\");"],"bootloadable":{"IframeShim":{"resources":[... . php文件返回一个长字符串,其中包含以下"css":["DSK\\/y"],"js":["V5Llk","1dVnw"],"onload":["goURI(\\"\\\\\\/procedure\\\\\\/376993639056176\\\\\\/?context=create\\");"],"bootloadable":{"IframeShim":{"resources":[...

What I want is to get the number 376993639056176 with javascript that is a server variable and keep a process with it. 我想要的是获取带有服务器变量javascript的数字376993639056176 ,并保留一个进程。 Can you help me please? 你能帮我吗?

Your server is returning a JSON with several information and you want the number part of the "onload" property of it. 您的服务器正在返回一个包含多个信息的JSON,并且您希望它的“ onload”属性的数字部分。 You can do the following 您可以执行以下操作

The following function will get only the digits from your String 以下函数将仅从您的字符串中获取数字

var serverJSONString = stringReturnedByServer();
var longUri = serverJSONString.onload[0]; //This will get only the "onload" string;
var decodedNumber = longUri.replace (/[^\d]/g, "");
alert(decodedNumber);

Here's a functional fiddle 这是一个实用的小提琴

If the only numbers in that string are actually the ones you're looking for you can use a regex like 如果该字符串中唯一的数字实际上是您要查找的数字,则可以使用正则表达式,例如

 var regex = new RegExp("[^0-9]*([0-9][0-9]*)[^0-9]*","g")
 var number = yourString.replace(regex,"$1");

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

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