English 中文(简体)
解释R regex
原标题:Explain this R regex
  • 时间:2012-04-15 16:37:15
  •  标签:
  • regex
  • r

最近,一个R问题的答案是,使用高压reg(。 LINK。 我喜欢这种反应,但可以把它概括起来,因为我不理解发生的事情(我用的是不同的数字价值,但这种价值实际上并没有产生任何有用的作用)。 难道有人会用零敲碎打碎碎打,解释发生什么?

x <- c("WorkerId", "pio_1_1", "pio_1_2", "pio_1_3", "pio_1_4", "pio_2_1", 
"pio_2_2", "pio_2_3", "pio_2_4")

gsub("([a-z])_([0-9])_([0-9])", "\1_\3\.\2", x)  #Explain me please

事先感谢你。

最佳回答

如果你具有特性,有两种数字由强调(例如1_2)分开,则该校将选择相应的特性和编号,并作为变量提供。 <代码>/1,2系指原表述中的对应论点:

\1 <- a
\2 <- 1
\3 <- 2

如上所示,操作<代码>gsub的结果表明,无论出现在哪里,都须填写相应的编号。 例如,a_1_2 <代码>a_2.1。

"\1_\3\.\2"
#  a_  2  .  1
问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签