我已经找了好几个小时了。这应该很容易,但我看不出是怎么做到的:
我有一个名为ds的dataframe,它包含一个结构如下的列:
name
"Doe, Mr. John"
"Worth, Miss. Jane"
我想把中间的词提取出来,放到一个新的专栏里。
#This is how I'm doing it now
ds$title <- NA
mr <- grep(", Mr. ", ds$name)
miss <- grep(", Miss. ", ds$name)
ds$title[mr] &l
假设我有这样一个字符串,我想在perl中进行处理。
hello|world|nice|to|meet|you
我想保留前三个管道符号和它们周围的文本,并丢弃剩下的字符串。所以,我最终会有这样的结果:
hello|world|nice|to
我想我想做这样的事:
substitute (zero or more non-pipes followed by a pipe)[3 times] followed by the rest of the string with a back reference to the piece of the regex where I matched the 3
我在寻找一种使用regex查找和替换句子的方法。正则表达式应该能够找到任意长度的句子。我可以用.*得到整个句子,但这不允许用\1替换。
FIND:
"QUESTION1" = "What is the day satellite called?"
"ANSWER1" = "The sun"
REPLACE:
<key>What is the day satellite called?</key>
<key>The sun</key>
stringg <- c("You are\ngoing to learn 3 things, the first one is not to extract, and\n2 and 3 are simply digits.", "....", "....",....)
在R中,我希望找到以“”结尾的所有listitem/字符串。在这个点之后,我想给它加上一个$符号。
grep("\\.$", stringg , value = TRUE) # this gives me the string from list which
我有如下字符串:
@property.one@some text here@property.two@another optional text here etc
它内部包含@.+?@字符串。
我想通过一个regexp匹配将所有这些“变量”捕获到组中,但这似乎是不可能的,因为regexp在重复时只返回最后捕获的组。
我使用perl regex捕获组来替换大量文件的模式。
文件示例1:
title="alpha" lorem ipsum lorem ipsum name="beta"
文件示例2:
title="omega" Morbi posuere metus purus name="delta"
为
title="beta" lorem ipsum lorem ipsum
title="delta" Morbi posuere metus purus
使用
find . -type f -exec perl
这是我的Regex
"(?<=\"body\":\")((?=\",|\"$)|.)+"
它标记身体上的一个字符串。例如,
"body":its my string
结果是
its my string
但是当我使用一个大的输入字符串时,我会得到这个错误。
Exception in thread "main" java.lang.StackOverflowError
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
at java
my $line = "The quick brown fox jumps over the lazy dog.";
while ($line){
$line =~ s/["",]//ig; #[] means to get rid of
#print $line
$line = lc($line); #lc is lowercase
while ($line=~m/\b(\w+\s\w+)\b/ig){ #[^ ] means any character except spaces and newline #($li
考虑到LogString的这一部分:
..。HTTP/1.1“206 391402 "-”AppleCoreMedia/1.0.0.8B117 (iPod;U;CPU OS 4_1 like Mac OS X;de_de)“
我需要匹配括号内的最后一个子字符串,以便从字符串中获取远程系统信息。
我不太喜欢正则表达式,但据我的理解,我不得不转义方括号,如"\(“和"\)”。
现在,为了匹配整个字符串,我想我必须这样做:
\(\.*\)与点匹配任何内容,"*“用于指定任意数量的点。
但不起作用。(\.*)或(.*)也不像您所期望的那样。
打开和关闭括号肯定有
我找不到返回给定输入的正则表达式,例如,1000000000是结果214。
这是我需要调整的文本:
lvl=100 (2626 KB for nbparts) 9522 possible passwords
lvl=101 (2652 KB for nbparts) 10 K possible passwords (10604)
lvl=102 (2678 KB for nbparts) 11 K possible passwords (11805)
...
lvl=213 (5564 KB for nbparts) 956 M possible passwords (956026029)
l
我有一个字符串如下:
30750 [uber-SubtaskRunner] INFO org.apache.hadoop.hive.ql.exec.Task - Hadoop job information for Stage-2: number of mappers: 1; number of reducers: 1
现在,我想从它中提取数字,并使用shell脚本将它们加起来。基本上,我想得到映射器和减速器的数量之和。根据“空格字符”拆分字符串似乎对我有效,任何regex模式都能做到这一点。
谢谢
我想修改一个文件夹中几个文件的名称。名称采用这种格式:
Name_name_name_name_XXXX.fa
我想:
XXXX_Name_name_name_name.fa
我厌倦了使用
for f in *.fa; do mv "${f/.fa/Name_name_name_name.fa}";done
output Name_name_name_name_XXXX_Name_name_name_name.fa
然后
for f in *.fa; do mv "${f/Name_name_name_name_//}"; done
删除4 name_name
关于R中的正则表达式,我有两个相关的问题:
1
我想把包含标点符号和字母的子字符串转换成大写字母.
示例:
Dr_dre to: DrDre
Captain.Spock to: CaptainSpock
spider-man to: spiderMan
2
我希望用下划线分隔符将camel大小写字符串转换为小写字符串。
示例:
EndOfFile to: End_of_file
CamelCase to: Camel_Case
ABC to: A_B_C
非常感谢,
卡玛希