Solved

RegEx not working while IndexOf does... why?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now