• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

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?
0
rmmarsh
Asked:
rmmarsh
  • 2
  • 2
2 Solutions
 
Jaime OlivaresCommented:
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 OlivaresCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now