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
Solved

regular expression needed after the $

Posted on 2014-02-26
27
204 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL400 max size 5 99
What's wrong with this web.config regex? 3 47
Problem to refer to value 8 62
How come this regular expression allows "e"? 14 44
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

791 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