Solved

RegEx not working while IndexOf does... why?

Posted on 2007-11-22
5
381 Views
Last Modified: 2008-02-26
I have this RegEx expression that I am trying to find in a string:

                    r = new Regex(">  $");
                    m = r.Match(bookInfo, m1.Index);
                    if (m.Success)

It doesn't find the string, yet the following does:

                index2 = bookInfo.IndexOf(">  $", m1.Index)

What is wrong with the RegEx statement?
0
Comment
Question by:rmmarsh
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20336694
the trailing dollar in the regex expression means "end of line"
the trailing dollar in the IndexOf call means "dollar sign"
0
 

Author Comment

by:rmmarsh
ID: 20336698
Great!  can you tell me how to 'escape' the dollar sign so I can use it in the expression?
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 500 total points
ID: 20336699
if you really want to match the dollar sign use:
r = new Regex(">  \$");
                   
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 20336703
Will it work?

 r = new Regex("*>  $*");
0
 

Author Comment

by:rmmarsh
ID: 20336714
Thanks, Jaime... I figured the escape out myself...

Thanks so much for your help... I was going NUTS!

r
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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