Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
特定搜索模式RegExp_Regex - Fatal编程技术网

特定搜索模式RegExp

特定搜索模式RegExp,regex,Regex,我不熟悉RegExp,但做了一些基础教程。从下面,我需要能够提取以下内容。您的帮助将增强我对RegExp的理解 提取字符串: 2016-02-17 19:59:18,182 GMT [transaction-Id=47ad8e96-1db8-4b41-85e5-9256fca485ab] [request_uri=/mydevice/2232234] [] INFO Response:{"executionTimeInMillis":54,"transactionId":"3191569800"

我不熟悉RegExp,但做了一些基础教程。从下面,我需要能够提取以下内容。您的帮助将增强我对RegExp的理解

提取字符串:

2016-02-17 19:59:18,182 GMT [transaction-Id=47ad8e96-1db8-4b41-85e5-9256fca485ab] [request_uri=/mydevice/2232234] [] INFO Response:{"executionTimeInMillis":54,"transactionId":"3191569800","success":false,"internalTransactionId":"47ad8e96-1db8-4b41-85e5-9256fca485ab","operationResults":[{"operation":"addDevice","code":"409","message":"Cannot add device"}]}
要提取的输出字符串值:

  • 47ad8e96-1db8-4b41-85e5-9256fca485ab
  • 22xs32234
  • {“操作”:“添加设备”,“代码”:“409”,“消息”:“无法添加设备”}
  • 提取$0、$1、$2

    提取$0、$1、$2

    Perl代码:

        #!/usr/bin/perl
    
        use strict;
        use warnings;
    
        my $string = '2016-02-17 19:59:18,182 GMT [transaction-Id=47ad8e96-1db8-    4b41-85e5-9256fca485ab] [request_uri=/mydevice/2232234] [] INFO Response:{"executionTimeInMillis":54,"transactionId":"3191569800","success":false,"internalTransactionId":"47ad8e96-1db8-4b41-85e5-9256fca485ab","operationResults":[{"operation":"addDevice","code":"409","message":"Cannot add device"}]}';
    
    
        if($string =~ /(?:transaction\-Id=)(.*)\] \[(?:request_uri=\/mydevice\/)(.*)\] \[.*(?:operationResults.:\[)(.*)\]\}$/ig){
           print "$1\n$2\n$3\n";
        }
        else{
            print "no match\n";
        }
    
    Perl代码:

        #!/usr/bin/perl
    
        use strict;
        use warnings;
    
        my $string = '2016-02-17 19:59:18,182 GMT [transaction-Id=47ad8e96-1db8-    4b41-85e5-9256fca485ab] [request_uri=/mydevice/2232234] [] INFO Response:{"executionTimeInMillis":54,"transactionId":"3191569800","success":false,"internalTransactionId":"47ad8e96-1db8-4b41-85e5-9256fca485ab","operationResults":[{"operation":"addDevice","code":"409","message":"Cannot add device"}]}';
    
    
        if($string =~ /(?:transaction\-Id=)(.*)\] \[(?:request_uri=\/mydevice\/)(.*)\] \[.*(?:operationResults.:\[)(.*)\]\}$/ig){
           print "$1\n$2\n$3\n";
        }
        else{
            print "no match\n";
        }
    
    (?
    (?)?