What's wrong with this RegEx?

This is my data:  {lhs: "1.00 U.S. dollar",rhs: "0.649941505 British pounds",error: "",icc: true}

This is the RegEx expression I was given, which doesn't work...   "rhs: \"(d*.d*)"  (I want to get the amount after "rhs")

What should it be?  (I know about a thimble-full about Regular Expressions, so I would appreciate someone helping me on this one...)

rmmarshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

erictronicCommented:
If you want the "dot" you should mask it with a leading \.
0
rmmarshAuthor Commented:
I tried rhs: \"(d*\.d*) and it said Invalid Escape Sequence (it's in a C# program).
0
käµfm³d 👽Commented:
If you want the "dot" you should mask it with a leading \.
You don't really have to escape the dot, since dot means "match any character," but generally, you would escape the dot to give clarity to the meaning of your regex.

You seem to have forgotten the leading slash on the first "\d".
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

käµfm³d 👽Commented:
...actually, both "\d"s.
0
käµfm³d 👽Commented:
In other words:

d   -  literal "d"
\d  -  any digit
0
rmmarshAuthor Commented:
didn't forget... didn't know about it!  :D

This is what I have now, with plenty of errors...

                Regex regex = new Regex("rhs: \"(\d*\.d*)");

It's complaining about both of the \d as being "unrecognized escape sequence"
0
rmmarshAuthor Commented:
Oops... I meant the \d and the ]. [dot]
0
käµfm³d 👽Commented:
P.S.

Two things:

* I see that you later noted that this was for C#. Always be sure to let us know which language or text editor you are using to execute your patterns. Different languages and different text editors use various syntaxes. "\d" might represent "any digit" in one language whereas "[[:digit:]]" might be used to mean the same thing in a different language/editor.

* You might find Expresso a useful utility in your regex arsenal. Loading up your pattern into the utility, you would quickly have seen the issue with your pattern:
untitled.PNG
0
rmmarshAuthor Commented:
This is what I have now...

                Regex regex = new Regex("rhs: \"(\d*\.\d*)");

It doesn't like any of the escape sequences ( \d's or \.)
0
käµfm³d 👽Commented:
It's complaining about both of the \d as being "unrecognized escape sequence"
In C#, string literals that have backslashes in them need to either have the backslashes escaped or you need to prefix the string with the "@" symbol.

For example:

Regex regex = new Regex("rhs: \"(\\d*\\.d*)");

Open in new window


vs

Regex regex = new Regex(@"rhs: ""(\d*\.d*)");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
P.S.

In the first code example, I didn't escape the backslash before the quotation mark because that backslash is escaping the quote so C# doesn't think that that quote signifies the end of string. In the @ version, the double-double-quote accomplishes the same thing, but you use an extra double-quote because the @ causes any backslashes to be treated as normal characters (i.e. they no longer escape anything--except for newlines and a couple of other whitespace characters, I believe).
0
rmmarshAuthor Commented:
Downloaded and ran Expresso... nice program!  However, when running the expression, there was no match against my data...
expresso.png
0
käµfm³d 👽Commented:
Remove the start and end quotes from your regex. It looks like you copy/pasted directly from your C# code, which is fine, but you need to leave out the quotation marks that denote a string literal in C#.

Note the difference in the "Regular Expression" pane of my screenshot and yours.
0
rmmarshAuthor Commented:
Argggghhhh!  I hate it when I forget something like that!

Thank you so very much for helping me out... this now works like a champ!  I really, really  appreciate your time.
0
käµfm³d 👽Commented:
NP. That's what we're here for! Glad you got it sorted out    = )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

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.