RegEx not working while IndexOf does... why?

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?
rmmarshAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
the trailing dollar in the regex expression means "end of line"
the trailing dollar in the IndexOf call means "dollar sign"
0
 
rmmarshAuthor Commented:
Great!  can you tell me how to 'escape' the dollar sign so I can use it in the expression?
0
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
if you really want to match the dollar sign use:
r = new Regex(">  \$");
                   
0
 
anarki_jimbelCommented:
Will it work?

 r = new Regex("*>  $*");
0
 
rmmarshAuthor Commented:
Thanks, Jaime... I figured the escape out myself...

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

r
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.