backreference Questions

2

Solved

I need to find in files (xml) date in this format 2021-06-25T21:17:51Z and replace them with this format 2021-06-25T21:17:51.001Z I thought about using regexp with sed but back references does not ...
Olympus asked 24/1, 2022 at 18:29

4

Solved

Given a regular expression containing capture groups (parentheses) and a string, how can I obtain all the substrings matching the capture groups, i.e., the substrings usually referenced by "\1", "\...
Bonfire asked 4/9, 2013 at 17:48

4

New to Python so please forgive my ignorance. I'm trying to modify backreferenced strings in a regular expression. Example: >>>a_string 'fsa fad fdsa dsafasdf u.s.a. U.S.A. u.s.a fdas a...
Windbound asked 2/9, 2011 at 3:48

17

Solved

I'm a regular expression newbie and I can't quite figure out how to write a single regular expression that would "match" any duplicate consecutive words such as: Paris in the the spring....
Proverb asked 12/5, 2010 at 21:51

5

I need to match a regex that uses backreferences (e.g. \1) in my Go code. That's not so easy because in Go, the official regexp package uses the RE2 engine, one that have chosen to not support bac...
Dekeles asked 31/5, 2014 at 10:33

4

Solved

Is there a way to back reference in the regular expression pattern? Example input string: Here is "some quoted" text. Say I want to pull out the quoted text, I could create the following expres...
Premillennial asked 27/4, 2010 at 15:21

4

Solved

I'm new to R and am stuck with backreferencing that doesn't seem to work. In: gsub("\\((\\d+)\\)", f("\\1"), string) It correctly grabs the number in between parentheses but doesn't apply the (c...
Soubriquet asked 26/8, 2014 at 13:2

2

Solved

I am learning the sed s/regexp/replacement/ command on linux. There are some numbers from phone.txt (555)555-1212 (555)555-1213 (555)555-1214 (666)555-1215 (777)555-1217 I'd like to use the reg...
Gobbler asked 30/12, 2018 at 19:32

5

Solved

You can backreference like this in JavaScript: var str = "123 $test 123"; str = str.replace(/(\$)([a-z]+)/gi, "$2"); This would (quite silly) replace "$test" with "test". But imagine I'd like to...
Eppes asked 15/3, 2010 at 14:44

4

Solved

I recently came across a puzzle to find a regular expression that matches: 5-character-long strings comprised of lowercase English letters in ascending ASCII order Valid examples include: aaa...
Halloo asked 30/6, 2017 at 14:33

4

Solved

Normally we would write the following to replace one match: namesRegex = re.compile(r'(is)|(life)', re.I) replaced = namesRegex.sub(r"butter", "There is no life in the void.") print(replaced) out...
Milliner asked 17/7, 2017 at 10:53

5

Solved

The sed manual clearly states that the available backreferences available for the replacement string in a substitute are numbered \1 through \9. I'm trying to parse a log file that has 10 fields. ...
Oxidimetry asked 30/11, 2010 at 20:15

5

I would like to clean some input that was logged from my keyboard with python and regex. Especially when backspace was used to fix a mistake. Example 1: [in]: 'Helloo<BckSp> world' [out]: '...
Serene asked 27/12, 2016 at 10:27

0

This article say: A backreference like \1 or \2 matches the string matched by a previous parenthesized expression, and only that string: (cat|dog)\1 matches catcat and dogdog but not cat...
Timbale asked 7/11, 2016 at 0:2

1

Solved

I was recently trying to answer a question, when I realised I didn't know how to use a back-reference in a regexp with Spark DataFrames. For instance, with sed, I could do > echo 'a1 b22 333' ...
Hanleigh asked 20/10, 2016 at 9:32

1

Solved

I'm new to Regular Expressions in Ruby, and I can't seem to find any solid documentation on what \k<name+0> means. It's the +0 part that I'm not getting. Here's an example - this Regexp matc...
Lumberyard asked 10/9, 2016 at 9:13

2

Solved

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 ...
Swoon asked 1/8, 2016 at 18:52

1

Solved

I got really confused about the usage of backreferences strings <- c("^ab", "ab", "abc", "abd", "abe", "ab 12") gsub("(ab) 12&qu...
Peridium asked 31/7, 2016 at 7:1

2

Solved

I understand how regular expressions got their name, and have read the related question (Why are regular expressions called "regular" expressions?), but am still wondering whether regular...
Dematerialize asked 29/3, 2016 at 11:34

3

I would like to patch some text data extracted from web pages. sample: t="First sentence. Second sentence.Third sentence." There is no space after the point at the end of the second sentence. Th...
Vaclava asked 22/8, 2012 at 2:42

1

Solved

I'm attempting this challenge: https://regex.alf.nu/4 I want to match all strings that don't contain an ABBA pattern. Match: aesthophysiology amphimictical baruria calomorphic Don't Match an...

6

Solved

What's the best way to clear/reset all regex matching variables? Example how $1 isn't reset between regex operations and uses the most recent match: $_="this is the man that made the new year ru...
People asked 18/4, 2012 at 20:35

4

Solved

Pretty straightforward; I can't seem to find anything definitive regarding PHP's preg_replace() supporting named backreferences: // should match, replace, and output: user/profile/foo $string = 'u...
Autarchy asked 10/3, 2011 at 3:32

4

Solved

I need to match any 'r' that is preceded by two different vowels. For example, 'our' or 'pear' would be matching but 'bar' or 'aar' wouldn't. I did manage to match for the two different vowels, but...
Sacks asked 13/4, 2015 at 12:46

3

Solved

I'm using capturing groups in regular expressions for the first time and I'm wondering what my problem is, as I assume that the regex engine looks through the string left-to-right. I'm trying to c...
Panjandrum asked 23/6, 2014 at 6:43

© 2022 - 2025 — McMap. All rights reserved.