Home > Backend Development > PHP Tutorial > 请教一个正则表达式

请教一个正则表达式

WBOY
Release: 2016-06-06 20:44:00
Original
1037 people have browsed it

我有一个字符串: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>
Copy after login

Ruby的

<code class="lang-ruby">string = "sasa<app>sasa<server>sasa<client>ddsdds";
array = string.scan(/\b\w+(?=\>)/);
</client></server></app></code>
Copy after login

<code class="lang-ruby">"sasa<app>sasa<server>sasa<client>ddsdds".scan(/\]*)\>/)
</client></server></app></code>
Copy after login

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>
Copy after login

$str = "sasasasasasaddsdds";
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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template