我有一个字符串:sasa<app>sasa<server>sasa<client>ddsdds</client></server></app>
,我想得到包在之中的字符串,也就是
[app, server, client]
,求教如何写正则表达式?最好是Ruby
我有一个字符串:sasa<app>sasa<server>sasa<client>ddsdds</client></server></app>
,我想得到包在之中的字符串,也就是
[app, server, client]
,求教如何写正则表达式?最好是Ruby
JavaScript的
<code class="lang-javascript">var string = "sasa<app>sasa<server>sasa<client>ddsdds"; string.match(/\b\w+(?=\>)/g); </client></server></app></code>
Ruby的
<code class="lang-ruby">string = "sasa<app>sasa<server>sasa<client>ddsdds"; array = string.scan(/\b\w+(?=\>)/); </client></server></app></code>
<code class="lang-ruby">"sasa<app>sasa<server>sasa<client>ddsdds".scan(/\]*)\>/) </client></server></app></code>
Perl的,抛个砖头,期待更简洁的代码
<code class="lang-perl">my $st="sasa<app>sasa<server>sasa<client>ddsdds"; my @arr; push @arr, $1 while ($st=~s/]+)>//); print join(",", @arr); </client></server></app></code>
$str = "sasasasa
preg_match_all("//U", $str, $matches);
Perl
<code>$a = 'sasa<app>sasa<server>sasa<client>ddsdds'; @ary = $a =~ //g; print "@ary"; </client></server></app></code>