0

I want to search for a specific pattern which contains a numeric "1" and replace it with the same string followed by the numeric "2". But if I call $12 then the output is the literal "$12". The regex engine seemingly tries to find the memory slot 12, but I intended to address the memory slot 1, and then write "2".

I tried to create a fiddle but this doesn't reproduce the error, so apparently it has something to do with my editor. I am using Dreamweaver CS6. If not with Dreamweaver then maybe my Dreamweaver settings.

Also, I just found this question which refers to my exact same problem – but the answer provided there doesn't work for me. $012 just writes "$012". I guess the Dreamweaver RegExp engine is peculiar like that.

Any ideas?

EDIT:

Given the example text …

This is item 1
This is house 3

… and the pattern ((?:item|house) )\d

what I tried | what I'm getting

$12     | $12
$012    | $012
\g{1}2  | \g{1}2
$g{1}2  | $g{1}2
$12 | item2   // or "house"
${1}2   | ${1}2
"$1"+2  | "item"+2

The desired result is always:

This is item 2
This is house 2

Because it was asked: yes, I am sure that the RegExp checkbox is activated and yes, I am sure that I'm in the Code view, not the Design view. I always work in Code view.

My Dreamweaver is CS6 Version 12.0 Build 5861.

Community
  • 1
  • 1
WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25

2 Answers2

1

This is a well-known bug in Dreamweaver. Fortunately, there are workarounds.

For argument's sake, let's say you are looking for letters and want to append a 2.

Method 1

I tested the following in Dreamweaver CS6.

Input: abc

Search in code view: ([a-z]+)

Replace: $12

Output in code view: abc2

Output in design view: abc2

Note that the output in code view is abc2, but because 2 encodes 2, on the web page you see abc2

Method 2: Two-step approach

Same search.

Replace: $1SOMETHINGDISTINCTIVE

Then search for SOMETHINGDISTINCTIVE and replace with 2

Finally

Of course some would argue that the real workaround is to work in Komodo IDE (or whatever editor they fancy), but that is not your question. :)

zx81
  • 41,100
  • 9
  • 89
  • 105
  • Hearing that it's a well-known bug gives me hope. But are you sure this works? I'm getting the literal output "$12". – WoodrowShigeru May 26 '14 at 11:56
  • I tested it in CS6 before posting the answer. Are you sure: (1) the regex box is checked in the find panel? (2) you searched in `code view` as specified by my answer? (If you search in `design view`, DW will escape the ampersand so you will have a literal `2` Don't know about the `$1` literal though, different version? – zx81 May 26 '14 at 12:00
  • Ooooooh! The "2" is the output in _design view!_ Then that's not a helpful answer: I'm trying to replace class names and such. – WoodrowShigeru May 26 '14 at 14:40
  • Of course, that would have worked. Simple and obvious. Sometimes I'm really blind. I ended up doing it by hand … – WoodrowShigeru May 27 '14 at 14:07
0

Lets say the Test String i.e. the string to match or select, is

aabbbccbbbaacc2

Case 1: Using Backreference for Matching or Selecting


Find/Search: (a+)(b+)(c+)\2\1\3\d

Case 2: Using Backreference for Match or Select & Replace


Say I Expect The Result as aacc9bbb

Find/Search: (a+)(b+)(c+)\2\1\3\d

Replace With: \1\039\2 or \1$039\2

So It's NOT \3 but \03 or $03, when it is followed by a numeric character, in the Replace With Field.