I have the following string:
<span class="ClassName @variable" title="ClassName @variable">Variable Title</span>
"ClassName", "variable" & "Variable 开发者_如何学运维Title" are paramerters.
Now I want to extract the "ClassName", "variable" and "Variable Title" from that sentence. How can I do that?
Javascript:
var matches = /<span class="(.*)" title="(.*)">(.*)<\/span>/.exec(str);
Where str
is your tag.
Then...
matches[1]=class
matches[2]=title
matches[3]=tag content
Note that you should really use a proper HTML parser for this kind of thing rather than Regex but never mind :)
Here is a Perl solution:
#!/usr/bin/perl
use 5.10.1;
use strict;
use warnings;
use Data::Dumper;
my $str = q!<span class="ClassName @variable" title="ClassName @variable">Variable Title</span>!;
my @list = $str =~ m#<span class="(\w+) @(\w+).*?>([\w\s]+)</span>#;
say Dumper \@list;
Output:
$VAR1 = [
'ClassName',
'variable',
'Variable Title'
];
精彩评论