diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 6d0e59a..5e04270 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -2529,7 +2529,7 @@ class DrupalWebTestCase extends DrupalTestCase {
         // Return the string.
         $value = count($parts) > 1 ? 'concat(' . implode(', \'"\', ', $parts) . ')' : $parts[0];
       }
-      $xpath = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $xpath);
+      $xpath = str_replace($placeholder, $value, $xpath);
     }
     return $xpath;
   }
diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test
index dde162e..77e9ea5 100644
--- a/modules/simpletest/simpletest.test
+++ b/modules/simpletest/simpletest.test
@@ -368,6 +368,8 @@ class SimpleTestBrowserTestCase extends DrupalWebTestCase {
 <body>
 <a href="link1">A "weird" link, just to bother the dumb "XPath 1.0"</a>
 <a href="link2">A second "even more weird" link, in memory of George O'Malley</a>
+<a href="link3">A \$third$ link, so weird it's worth $1 million</a>
+<a href="link4">A fourth link, containing alternative \\1 regex backreferences \\2</a>
 </body>
 </html>
 EOF;
@@ -379,6 +381,12 @@ EOF;
 
     $urls = $this->xpath('//a[text()=:text]', array(':text' => 'A second "even more weird" link, in memory of George O\'Malley'));
     $this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.');
+
+    $urls = $this->xpath('//a[text()=:text]', array(':text' => 'A $third$ link, so weird it\'s worth $1 million'));
+    $this->assertEqual($urls[0]['href'], 'link3', 'Match with a regular expression back reference symbol (dollar sign).');
+
+    $urls = $this->xpath('//a[text()=:text]', array(':text' => 'A fourth link, containing alternative \\1 regex backreferences \\2'));
+    $this->assertEqual($urls[0]['href'], 'link4', 'Match with another regular expression back reference symbol (double backslash).');
   }
 }
 
