finding words surround by quotations perl

前端 未结 2 614
星月不相逢
星月不相逢 2020-12-20 00:44

I am reading another perl file line by line and need to find any words or set of words surround by single or double quotations. This is an example of the code I am reading i

2条回答
  •  天涯浪人
    2020-12-20 00:54

    Maybe you can have more than one "string" to capture per line, one solution could be:

    while(my $line=) {
        while( $line =~ /[\'\"](.*?)[\'\"]/g ) {
            print "matched: '$1'\n";
        }
    }
    

    ie, input:

    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    my $string = 'Hello World!' . 'asdsad';
    print "$string\n";
    

    and executing the code will give you:

    matched: 'Hello World!'
    matched: 'asdsad'
    matched: '$string\n'
    

提交回复
热议问题