[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to force $1 to be a literal instead of submatch when using regexp.replace method?

Posted on 2011-10-30
4
Medium Priority
?
972 Views
Last Modified: 2012-05-12
This is mainly for the regular expressions zone.

Line1 below works exactly as expected. It replaces the pattern with the text "works fine"
But, line2 fails, because it interprets the $1 as submatch #1 which is the word "quick".

line1: MsgBox RegExpReplace("the quick brown fox", "(quick|fast) brown", "works fine")
line2: MsgBox RegExpReplace("the quick brown fox", "(quick|fast) brown", "See Cell $A$1")

I tried using the standard escape character  "$A\$1" but that did not work.

I came up with the following workaround, but it is ugly, and I am sure there is a better way

msgbox replace(RegExpReplace("the quick brown fox", "(quick|fast) brown", "xxxxxx"),"xxxxxx","See Cell $A$1")

rberke

0
Comment
Question by:rberke
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 37054097
Try doubling-up the dollar symbol:  $$1.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 37054157
That should work.  At least it did when I tested it just now :)

Adding that as a comment to http://www.experts-exchange.com/Programming/Languages/Visual_Basic/A_1336-Using-Regular-Expressions-in-Visual-Basic-for-Applications-and-Visual-Basic-6.html, which is where that function came from...
0
 
LVL 5

Author Closing Comment

by:rberke
ID: 37054158
Thanks,

I knew there would be an easy way.

Bob
0
 
LVL 5

Author Comment

by:rberke
ID: 37054162
and thanks again to mathewspatrick for his wonderful function which I use every day.


Bob
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Bada platform is becoming more and more famous this days and people talking about same. Some friends included those who have bada OS mobile asked me "what is bada?"and "what its features?". That encouraged me to research and write this article. [st…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question