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
-2
votes
2 answers

Array and backreference

I'm new to backreference. I have an array and need to replace it in string. Here's my try: var cc = ["book","table"]; var str = "The $1 is on the $2"; var newstr = str.replace(cc, "$2, $1"); console.log(newstr)
Tropicalista
  • 3,097
  • 12
  • 44
  • 72
-3
votes
3 answers

How to remove repeated sequence of characters in a string?

Imagine if: $string = "abcdabcdabcdabcdabcdabcdabcdabcd"; How do I remove the repeated sequence of characters (all characters, not just alphabets) in the string so that the new string would only have "abcd"? Perhaps running a function that returns…
1 2 3
…
26
27