Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

regular expression needed after the $

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
metatonka
Asked:
metatonka
  • 13
  • 13
1 Solution
 
Terry WoodsIT GuruCommented:
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
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
Not code it is a regular expression elevator within a workflow program. see screen shot attached. thanks
value.jpg
0
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
almost...
got

565;

how do we remove the ";"
0
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
(?<=[$])[0-9]{1,} = 1160;
darn
the remaining ";" is still there
any suggestions?
thnaks
0
 
metatonkaAuthor Commented:
what works best from past questions is  .NET's regex library for this regular expression interpreter.
0
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
How are the other regular expressions (that work ok) different?
0
 
Derek JensenCommented:
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
 
metatonkaAuthor Commented:
Yes, i tried replacing \d with [0-9] and the ";" was there.
(?<=[$])[0-9]{1,} = 1160;
0
 
metatonkaAuthor Commented:
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
 
metatonkaAuthor Commented:
i really appreciate your help!
0
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
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
 
Terry WoodsIT GuruCommented:
Does the provider of the software offer support in any way? It may be worth contacting them to see if they can help.
0
 
metatonkaAuthor Commented:
Yes, i have contacted the vendor and they suggest using regular expressions that are compatible to the  .NET's regex library.
0
 
Terry WoodsIT GuruCommented:
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
 
Terry WoodsIT GuruCommented:
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
 
Terry WoodsIT GuruCommented:
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
 
metatonkaAuthor Commented:
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

Industry Leaders: 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!

  • 13
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now