Questions tagged [backreference]

Back references are regular expression constructs that make use of capturing in regex to perform replacement based on parts of the matched string captured during a match sequence in the regexp pattern.

Back references and s are regular expression constructs that makes use of capturing in to perform matching and replacement that remembers parts of the matched string during a match sequence in the regexp pattern.

The back-referencing constructs present in all engines are \1 to \9, where \1 back-reference references the first ( ) capturing group.

Read more:

392 questions
0
votes
1 answer

How do I return a portion of a string with ack (or an equivalent)?

I have a line in a file that looks like this: $db['foo']['database'] = 'bar'; I want to use ack or grep or something to return bar out of that string. So far I have: ack '^\$db\['\''foo'\''\]\['\''database'\''\] = '\''([\w_]+)'\' $file But don't…
futuraprime
  • 5,468
  • 7
  • 38
  • 58
0
votes
1 answer

How Many Parameters Allowed in VBA Regex .Replace Method?

! I am working with the replace method of VBA Regex and am wondering how many parameters it can take? I've seen the msdn page that gives lots of different options, but I'm unsure about which to use. Here's the link to that page: MSDN Page:…
buck1112
  • 504
  • 8
  • 24
-1
votes
3 answers

Why is my Back Reference in my Regular Expression Not Working?

I wrote a regular expression trying to match some html code but I can't quite it to work. I'm having a problem with the part after "wp-caption". class=(["\'])(?:[\w\s])*?wp-caption[\s\1] The code I want to…
BFTrick
  • 5,211
  • 6
  • 24
  • 28
-1
votes
1 answer

Numerical reference for backreference not working out in Python

I was trying to deal with difflib matches that return double word place names when only one of the words has been used to make the match. That is: when I do the difflib regex substitution I get a double up of the second word. Approach: capture…
Dave
  • 687
  • 7
  • 15
-1
votes
1 answer

GNU grep, backreferences and wildcards

Using grep (GNU grep 3.3) to search for all words with three consecutive double-letters (resulting in "bookkeeper"): grep -E "((.)\2){3}" /usr/share/dict/american-english Changing this to search for words with three double-letters, each of them…
SlowFox
  • 63
  • 5
-1
votes
1 answer

Backrefence without matching it on find result

Consider the text structure (Title)[#1Title-link] (Chapter1)[#Chapter1-link] (Chapter2)[#Chapter2-link] (Chapter3)[#Chapter3-link] How can i backrefence to [#Title-link] without matching it on find result. Im trying to change …
rinze
  • 1
  • 1
-1
votes
2 answers

Capture the latest in backreference

I have this regex (\b(\S+\s+){1,10})\1.*MY and I want to group 1 to capture "The name" from The name is is The name MY I get "is" for now. The name can be any random words of any length. It need not be at the beginning. It need on be only 2 or…
-1
votes
1 answer

Use dynamic number of backreferences

Is there a way to loop through all backreferences in a regex replace scenario? To better understand what I am asking for: Given you have the following text Item 1, Item 2, Item 3 When you have a regex that matches an arbitrary number of items like…
baumgarb
  • 1,955
  • 3
  • 19
  • 30
-1
votes
2 answers

Regex in Android JAVA - How to specify more than 9 backreferences?

I use multiple groups in a Regex search and replace many parts of a string. I use $1 $2 etc in Android JAVA when using String.replaceFirst. If I use more than nine groups in my Regex search when trying to reference them in replaceFirst for example…
zeroprobe
  • 580
  • 1
  • 8
  • 19
-1
votes
1 answer

Parentheses in Block Brackets in RegEx

I need a RegEx that matches the following: (whatever) 3.4 Temp (whatever) 7.8 Name (whatever) 10.0 Other Name Basically, it has to match whatever in the beginning, and then either two spaces, two digits, a dot and a digit or three spaces,…
Alex Beals
  • 1,965
  • 4
  • 18
  • 26
-1
votes
1 answer

Using backreferences for backreferencesing to a pattern

Consider (\w[0-9]).*\1 RegEx, it matches to d1akdhfafd1, R2ddsfasfasfdsfdR2, etc. . Is is possible to write a RegEx that that match to following too: D1dfsadfadsfE3, z6adfdasfdfr2, e3654654e0 ,....? \w[0-9] is just an example, please consider…
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
-1
votes
1 answer

javascript regex backrefence

This is the continuation of php regex: phone number 7-12 digits may contain hypen or space I'm still trying to understand backreferences. The following is the JavaScript code I came up with to test backreferences. When I run this code only null is…
vaanipala
  • 1,261
  • 7
  • 36
  • 63
-2
votes
1 answer

How to separare backreference and alphanumberic values in psql

I have a field that contains a string (Column name of another table) "call_records_2001.start_time" I need to replace it with "call_records_2002.start_time" I wanted this should be working for similar patterns, call_records_2001.end_time,…
-2
votes
1 answer

Regex Backeference Multiplying

I am trying to learn regex and one of the exercise I am trying to solve is as follows: I have a string: "london new york" that I am trying match with regex. and pattern is like this: r"(..o(.)).+(\2)*" Result is ndon new york. As far…
jdoe
  • 59
  • 10
-2
votes
2 answers

Use multiple backreferences in a function to produce the replacement value in stringr functions in R

How can I use multiple backreferences in a function to produce the replacement in stringr functions, for example, in stringr::str_replace()? An example: suppose I want the replacement to be rounded to a whole number and concatenated into one string…
stevec
  • 41,291
  • 27
  • 223
  • 311
1 2 3
26
27