简体   繁体   English

如何使用Regex访问此数据

[英]How can I used Regex to access this data

This is the data in the JS file: 这是JS文件中的数据:

    [{\"value\":16633,\"name\":\"fdgdfgdf@joindiaspora.com\"},{\"value\":16910,\"name\":\"jamesw@wk3.org\"},{\"value\":16911,\"name\":\"sdasfasf@joindiaspora.com\"}]" ),

and I want to output it in a 2d array something like: 我想在2d数组中输出它,如:

value name, 价值名称,

16633 fdgdfgdf@joindiaspora.com, 16633 fdgdfgdf@joindiaspora.com,

16910 jamesw@wk3.org, 16910 jamesw@wk3.org,

16911 sdasfasf@joindiaspora.com 16911 sdasfasf@joindiaspora.com

here is my code so far: 这是我目前的代码:

$.ajax
({  
    async: false,
    type: 'GET',
    url: 'https://wk3.org/conversations/new',
    success: function(data) 
    {
        var matches;
        var Ragex = /\\"value\\":\\"(.*)\\",\\"name\\":\\"(.*)\\"},/g           //need to sort out the REGEX so it goes through each name and ID seeing if it equals ID
        while ((matches = Ragex.exec(data)) !== null)
        {
            console.log(matches);
        }
    }

});

which outputs: 哪个输出:

["\"value\":\"16633\",\"name\":\"fdgdfgdf@joindiaspora.com\"},…"},{\"value\":\"16910\",\"name\":\"jamesw@wk3.org\"},", "16633\",\"name\":\"fdgdfgdf@joindiaspora.com\"},{\"value\":\…"name\":\"sdasfasf@joindiaspora.com\"},{\"value\":\"16910", "jamesw@wk3.org", index: 92, input: "<script>↵  //<![CDATA[↵    $(document).ready(funct…it" value="Send" />↵</div>↵</form>↵</div>↵</div>↵"]

you wish to capture ? 你想捕捉? in \\":\\"?\\" , right ? \\":\\"?\\" ,对吧?

I am not familiar to diaspora. 我不熟悉侨民。

In python, pattern (\\":\\").(\\") should make it 在python中,pattern (\\":\\").(\\")应该成功

$.ajax
({  
    async: false,
    type: 'GET',
    url: 'https://wk3.org/conversations/new',
    success: function(data) 
    {
        var matches;
        var name;
        var regex = /{\\"value\\":\\"([^"]*)\\",\\"name\\":\\"([^"]*)\\"}/g         //need to sort out the REGEX so it goes through each name and ID seeing if it equals ID
        while ((matches = regex.exec(data)) !== null)
        {
            console.log(matches);
            var name = matches[2];
            if(name == ID)
            {
                result = matches[1];
            }
            else
            {
                console.log("FAIL");
                //this sends a message to me only
                //need to add error trapping saying recipient cannot be found!
            }
        }
    }

});

暂无
暂无

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

相关问题 如何使用带有访问权限和VBA的正则表达式来匹配字符串 - How can I matche an string using regex with access and VBA 如何在Perl的正则表达式中访问命名捕获组中的值? - How can I access the value in a named capture group in a regex in perl? 如何使用Regex查找我是否在多个不同位置使用相同的字符? - How can I use Regex to find if I used the same character in multiple different locations? 如何强化与 preg_match/replace 正则表达式一起使用的输入? - How can I harden input used with preg_match/replace regex? 正则表达式可用于裁剪吗? - Can regex be used for cropping? 如何判断我的perl进程是否使用了正则表达式$ PREMATCH / $ MATCH / $ POSTMATCH变量(或短等价$&#39;/ $&#39;/ $&)? - How can I tell if my perl process has used the regex $PREMATCH/$MATCH/$POSTMATCH vars (or the short equivilents $`/$'/$&)? 如何将参数传递给正则表达式构造函数,并在 String.matchAll 方法中使用 - How can I pass parameter to regex constructor, and used in String.matchAll method 如何将此 JavaScript 逻辑移植为单行 RegEx 以在 PHP 中使用? - How can I port this JavaScript logic as a single-line RegEx to be used in PHP? 如何使用正则表达式在引号之间查找数据? - How can I use regex to find data between quotation marks? 如何使用正则表达式从消息中过滤此数据? - How can I filter this data out of a message with regex?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM