我现在有一个匹配任何数字的正则表达式:
/(\d)/
Run Code Online (Sandbox Code Playgroud)
现在我想修改它不拾取 1,所以它应该捕获 238、12、41,而不是 1。
有没有人看到这样做的方法?
谢谢
我在R中有以下向量:
x <- c("id: capture this , something: the useless chunk , otherstuff: useless , more stuff")
Run Code Online (Sandbox Code Playgroud)
我希望得到字符串"捕获这个".我使用过这个正则表达式:
library(rex)
r <- rex(
start,
anything,
"id: ",
capture(anything),
" , ",
anything
)
r
# > r
# > ^.*id: (.*) , .*
re_matches(x,r)
Run Code Online (Sandbox Code Playgroud)
但我得到的是:
> re_matches(x,r)
1
1 capture this , something: the useless chunk , otherstuff: useless
Run Code Online (Sandbox Code Playgroud)
它捕获我想要的东西,但也捕获字符串的其余部分.我只想要"捕获这个"字段.即使我使用gsub函数:
gsub("^.*id: (.*) , .*", "\\1", x)
Run Code Online (Sandbox Code Playgroud)
使用相同的正则表达式我得到了相同的结果.
这是R: R版本3.1.3(2015-03-09)的信息 - "Smooth Sidewalk"版权所有(C)2015统计计算平台的R基础:x86_64-pc-linux-gnu(64位)
和ubuntu的版本: 没有LSB模块可用.经销商ID:Ubuntu描述:Ubuntu 14.04.2 LTS版本:14.04代号:trusty
首先,我不会每天在java中编写代码,尽管我对大多数方面都有些熟悉.
我有一个integer
存在多个值的数组.然后我接受这个数组并转换为String
数组,这样我就可以使用正则表达式来查找作为数组元素的所有偶数值.
public static void main (String[] args) {
Pattern p = Pattern.compile("[0-9]*[02468]\\b");
int[] nums = {1, 6, 7, 8, 9, 21, 22, 23, 33, 34, 35, 42};
String[] vals = Arrays.toString(nums).split("[\\[\\]]")[1].split(", ");
List<String> results = new ArrayList<String>();
for (String s : vals) {
if (p.matcher(s).matches()) {
results.add(s);
}
}
System.out.println(results);
}
Output // [6, 8, 22, 34, 42]
Run Code Online (Sandbox Code Playgroud)
这个问题可能看起来很愚蠢或无关紧要,但是他们是一种不使用正则表达式来执行此操作的方法吗?
我有以下格式的电话号码:
$number = '06-20-459-3698';
Run Code Online (Sandbox Code Playgroud)
我需要计算其中至少有5位偶数的电话号码的数量.
我想我可以用正则表达式/.*[.*[02468]]{5}.*/
来做,但是如何在一个[]对中包含两个不同的项目列表?
我正在使用perl.
提前致谢.
我有关键字列表:
String[] keywords = {"xxxx", "yyyy", "zzzz"};
String[] another = {"aaa", "bbb", "ccc"};
Run Code Online (Sandbox Code Playgroud)
我正在尝试识别其中一个关键字后面跟一个空格然后跟着一个"另一个"字的文本.
如果我使用:
Pattern pattern = Pattern.compile(keywords+"\\s"+another);
Run Code Online (Sandbox Code Playgroud)
这会在运行时抛出异常:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 57
[Ljava.lang.String;@3dd4ab05\s[Ljava.lang.String;@5527f4f9
^
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我有一组像这样的字符串:
uc001acu.2;C1orf159;chr1:1046736-1056736;uc001act.2;C1orf159;
Run Code Online (Sandbox Code Playgroud)
我需要在两个分号之间提取子字符串,我只需要第一次出现.
结果应该是: C1orf159
我试过这段代码,但它不起作用:
import re
info = "uc001acu.2;C1orf159;chr1:1046736-1056736;uc001act.2;C1orf159;"
name = re.search(r'\;(.*)\;', info)
print name.group()
Run Code Online (Sandbox Code Playgroud)
请帮我.谢谢
我正在使用Perl TMDB
模块
我如何从下面的代码中获取示例中的元素
my $width = '1000'
和 my $file_path = "/yDIVWFJqFLIeS8E1R6GG9uwPMS3.jpg"
my @images = $movie->images;
# print " <p>backdrops </p>";
print OUT JSON::to_json(\@images) ; ## Dump.txt below
foreach my $image (@images) {
#print $movie->cast;
my $backdrops = $image->{backdrops};
my $posters = $image->{posters};
#print " <p>backdrops" . JSON::to_json(\@backdrops) . "</p>";
foreach my $backdrop ($image{backdrops}) {
my $width = $backdrop->{width};
my $file_path= $backdrop->{file_path};
print " <p>backdrops </p>";
print "<div>width : $width <br />$file_path : $file_path </div>";
}
}
Run Code Online (Sandbox Code Playgroud)
Dump.txt的示例
[{ …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个正则表达式来匹配大括号之间的文本.
{one}{two}{three}
Run Code Online (Sandbox Code Playgroud)
我希望每个都作为单独的组,one
two
three
分开.
我尝试过Pattern.compile("\\{.*?\\}");
只删除第一个和最后一个花括号
谢谢.
我想从文件中提取数字(整数和浮点数)(排除所有特殊符号和字母)。所有位置的数字。
import re
file = open('input_file.txt', 'r')
file = file.readlines()
for line in file:
line=re.findall(r'\d+|\d+.\d+', line)
print line
Run Code Online (Sandbox Code Playgroud)