Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regular expression needed after the $

Posted on 2014-02-26
27
Medium Priority
?
209 Views
Last Modified: 2014-03-18
Following data choices:

Not Needed
2hrs=$100
3hrs=$130
4hrs=$160
5hrs=$190
6hrs=$220
7hrs=$250
8hrs=$280
9hrs=$310
10hrs=$340
11hrs=$370
12hrs=$400

.net compatible regular expression

1) one of the above row is choose as the answer
2) regular expression evaluates the choice
3) need the numbers after the $ not including
4) if Not needed is the answer result is zero or nothing but no error.

thanks
0
Comment
Question by:metatonka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 13
27 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890055
I can't provide .NET code (I use PHP), but a pattern that should work with a regex match is:
\$(\d+)

Open in new window

The number will be captured in the first group.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890066
This might help shed some light on the code (I selected C#.NET), but you may actually want  VB.NET since you didn't say either way: http://www.myregextester.com/?r=ac0e0f68
0
 

Author Comment

by:metatonka
ID: 39890123
when i use this
\$(\d+)
and i use this value = 9hrs=$310

i get the following:
$310;

we are almost there, how to i get the number without the "$" AND without the ";"

thank you
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890138
You need to get the value captured from the group. If you paste your code, I may be able to say how to do it. If you look at the code at my link above, it outputs the captured value using m.Groups[gIdx].Value

In your case, you know you want the first group, so you'd just use m.Groups[1].Value
0
 

Author Comment

by:metatonka
ID: 39890149
Not code it is a regular expression elevator within a workflow program. see screen shot attached. thanks
value.jpg
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890155
In that case, perhaps you could try pattern:
(?<=\$)\d+

Open in new window


The (?<=\$) part of the pattern is a "positive lookbehind" which requires a $ character before the number but doesn't capture it as part of the match.
0
 

Author Comment

by:metatonka
ID: 39890201
almost...
got

565;

how do we remove the ";"
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890213
I'm not sure why you're getting that as part of your result when it's not in the pattern. Is it perhaps a standard termination character added to the end of any captured value? Or do you think it originates from your data?
0
 

Author Comment

by:metatonka
ID: 39890234
i dont know.
has not been a problem with other regular expression.
but i can run another regular expression
and replace ";" with blank
see attached screen capture
value2.jpg
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39890418
At this point, having a play around with how the Extract option works on your software is probably the best way forward. Try changing the pattern in different ways to see when the ; character gets added to your result, and when it doesn't.

Note there is another way to match numbers other than \d - you can use [0-9] instead, in case it makes a difference. Also, instead of the + (which means match one or more, and as many as possible, of the previous character/group) you can use {1,}

\$ can be replaced with [$] too.

This means the pattern:
(?<=[$])[0-9]{1,}

Open in new window

should give the same result, but in your case where something unexpected is happening, there's a chance it may behave differently.
0
 

Author Comment

by:metatonka
ID: 39891755
(?<=[$])[0-9]{1,} = 1160;
darn
the remaining ";" is still there
any suggestions?
thnaks
0
 

Author Comment

by:metatonka
ID: 39892583
what works best from past questions is  .NET's regex library for this regular expression interpreter.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39892917
Did you work out whether the ; character was from your data, or whether it was added in along the way? Does it still appear with a simpler pattern like \d ?
0
 

Author Comment

by:metatonka
ID: 39893106
No, the ";" is not a character from the data.
one of the example of data is "11hrs=$1160"

In the other regular expressions dont have this problem.

If i only use "\d" i get the following:
1;1;1;1;6;0;

I have requested other regular expressions and " .NET's regex library " is compatible with the interpreter that i am using.

any suggestions?
thanks
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39893150
How are the other regular expressions (that work ok) different?
0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39907021
Have you tried @Terry's suggestion of using [0-9] instead of \d? It looks to me like the ; is coming from the replace portion of the regex, maybe:

Look for: \d            (or \d+ or whatever)
Replace with: $0;   (where $0 refers to the entire match of the regular expression, and would be handled automatically by the software, most likely)

Might that be possible?
0
 

Author Comment

by:metatonka
ID: 39911399
Yes, i tried replacing \d with [0-9] and the ";" was there.
(?<=[$])[0-9]{1,} = 1160;
0
 

Author Comment

by:metatonka
ID: 39911401
How are the other regular expressions (that work ok) different?
Since i am a newbie on regular expressions all i can tell you is that the other regular expressions are compatible to  .NET's regex library.
0
 

Author Comment

by:metatonka
ID: 39911402
i really appreciate your help!
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39916383
Where the other regular expressions you've tried worked ok, was it because you weren't using the Extract option as shown in your screenshots? Perhaps adding a ; character is a standard feature of the software?
0
 

Author Comment

by:metatonka
ID: 39920802
Perhaps adding a ; character is a standard feature of the software?
No other regular expression provided has had this problem. Have checked, not a standard feature of the software
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39921780
Does the provider of the software offer support in any way? It may be worth contacting them to see if they can help.
0
 

Author Comment

by:metatonka
ID: 39921795
Yes, i have contacted the vendor and they suggest using regular expressions that are compatible to the  .NET's regex library.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39921812
Have you use the Extract option elsewhere, without the problem occurring?

Perhaps you could use trial and error to find the simplest case that causes the semi-colon to appear (eg about the simplest pattern you could use is just "1"), and then get back in touch with the software vendor. It's pretty clear that the software is not correctly working as the .NET regex library does.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39921824
One more thought: if you click the "Replace Text" radio button, is there anything (such as a semi-colon character) in the "Replacement text" box as shown in your screenshot? If so, perhaps that could be causing the issue even when the Extract radio button is active.
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 1000 total points
ID: 39921850
It's also interesting you said earlier:
If i only use "\d" i get the following:
1;1;1;1;6;0;
That looks more like a Split operation than an Extract one. Are you sure you've got the correct radio button checked? If so, then there may be a software bug that is somehow causing it to do the wrong command. Sometimes, doing something like deleting the operation (or whatever a processing step in your software is called) and starting from scratch can resolve that kind of issue.

Alternatively, working around the issue by adding an extra Replacement step to replace the ; character with an empty string may be an easy way to just deal with the problem and move on.
0
 

Author Comment

by:metatonka
ID: 39937073
Alternatively, working around the issue by adding an extra Replacement step to replace the ; character with an empty string may be an easy way to just deal with the problem and move on.

Unfortunately doing this causes another problem that the result is text and not a number. I need to have the original result a number so as to be able to add. This one example is a part of 15 items that the solution will be acted upon. so each workaround requires the solution to be replicated 15x.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

730 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