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

请教一个正则表达式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:44:00
Original
1077 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的

var string = "sasa<app>sasa<server>sasa<client>ddsdds";
string.match(/\b\w+(?=\>)/g);
Copy after login

Ruby的

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

"sasa<app>sasa<server>sasa<client>ddsdds".scan(/\<([^>]*)\>/)
Copy after login

Perl的,抛个砖头,期待更简洁的代码

my $st="sasa<app>sasa<server>sasa<client>ddsdds";
my @arr;
push @arr, $1 while ($st=~s/<([^>]+)>//);

print join(",", @arr);
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";
</code>
Copy after login
Related labels:
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
Latest Issues
Error when executing ruby ​​script
From 1970-01-01 08:00:00
0
0
0
Ruby - Convert nested objects to json?
From 1970-01-01 08:00:00
0
0
0
ruby - how to update submodels in rails
From 1970-01-01 08:00:00
0
0
0
How do you configure VIM on Mac?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template