backreference

Is there an equivalent of “&” in R's regular expressions for backreference to entire match?

狂风中的少年 提交于 2020-05-08 08:14:49
问题 When I use vim, I often use & to backreference the entire match within substitutions. For example, the following replaces all instances of "foo" with "foobar": %s/foo/&bar/g The benefit here is laziness: I don't have to type the parenthesis in the match and I only have to type one character instead of two for the backreference in the substitution. Perhaps more importantly, I don't have figure out my backrefrences while I'm typing my match, reducing cognitive load. Is there an equivalent to

Is there an equivalent of “&” in R's regular expressions for backreference to entire match?

人走茶凉 提交于 2020-05-08 08:13:26
问题 When I use vim, I often use & to backreference the entire match within substitutions. For example, the following replaces all instances of "foo" with "foobar": %s/foo/&bar/g The benefit here is laziness: I don't have to type the parenthesis in the match and I only have to type one character instead of two for the backreference in the substitution. Perhaps more importantly, I don't have figure out my backrefrences while I'm typing my match, reducing cognitive load. Is there an equivalent to

Is there an equivalent of “&” in R's regular expressions for backreference to entire match?

丶灬走出姿态 提交于 2020-05-08 08:12:29
问题 When I use vim, I often use & to backreference the entire match within substitutions. For example, the following replaces all instances of "foo" with "foobar": %s/foo/&bar/g The benefit here is laziness: I don't have to type the parenthesis in the match and I only have to type one character instead of two for the backreference in the substitution. Perhaps more importantly, I don't have figure out my backrefrences while I'm typing my match, reducing cognitive load. Is there an equivalent to

Use previous backreference as name of named capture group

﹥>﹥吖頭↗ 提交于 2020-02-28 07:27:00
问题 Is there a way to use a backreference to a previous capture group as the name of a named capture group ? This may not be possible, if not, then that is a valid answer. The following: $data = 'description: some description'; preg_match("/([^:]+): (.*)/", $data, $matches); print_r($matches); Yields: ( [0] => description: some description [1] => description [2] => some description ) My attempt using a backreference to the first capture group as a named capture group (?<$1>.*) tells me it's

Negating a backreference in Regular Expressions

纵饮孤独 提交于 2020-01-14 06:47:12
问题 if a string has this predicted format: value = "hello and good morning" Where the " (quotations) might also be ' (single quote), and the closing char (' or ") will be the same as the opening one. I want to match the string between the quotation marks. \bvalue\s*=\s*(["'])([^\1]*)\1 (the two \s are to allow any spaces near the = sign) The first "captured group" (inside the first pair of brackets) - should match the opening quotation which should be either ' or " then - I'm supposed to allow

How to replace all the blanks within square brackets with an underscore using sed?

对着背影说爱祢 提交于 2020-01-02 10:20:34
问题 I figured out that in order to turn [some name] into [some_name] I need to use the following expression: s/\(\[[^ ]*\) /\1_/ i.e. create a backreference capture for anything that starts with a literal '[' that contains any number of non space characters, followed by a space, to be replaced with the non space characters followed by an underscore. What I don't know yet though is how to alter this expression so it works for ALL underscores within the braces e.g. [a few words] into [a_few_words].

Java Regex - capture string with single dollar, but not when it has two successive ones

一笑奈何 提交于 2020-01-02 08:16:22
问题 I posted this question earlier. But that wasn't quite the end of it. All the rules that applied there still apply. So the strings: "%ABC%" would yield ABC as a result (capture stuff between percent signs) as would "$ABC." (capture stuff after $, giving up when another dollar or dot appears) "$ABC$XYZ" would too, and also give XYZ as a result. To add a bit more to this: "${ABC}" should yield ABC too. (ignore curly braces if present - non capture chars perhaps?). if you have two successive

How to apply a function on a backreference?

跟風遠走 提交于 2019-12-30 07:06:08
问题 Say I have strings like the following: old_string = "I love the number 3 so much" I would like to spot the integer numbers (in the example above, there is only one number, 3 ), and replace them with a value larger by 1, i.e., the desired result should be new_string = "I love the number 4 so much" In Python, I can use: r = re.compile(r'([0-9])+') new_string = r.sub(r'\19', s) to append a 9 at the end of the integer numbers matched. However, I would like to apply something more general on \1 .