Solved

RegEx not working while IndexOf does... why?

Posted on 2007-11-22
5
374 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 29

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
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…

840 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