This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Regular expression for finding currency values but not dates in text
Hi this is my text can u please provide reg ex for finding currency only as shown below:
97.38
86.16
3,259.81
28,781.07
problem here is it is getting value from date also because it is in the of the currency so it should restrict the value from date
Ex text:
13/07/2011 EA35906558 - 13.07.11 8054 97.38
14/07/2011 EA35906566-14.07.11 8054 86.16
14/08#011 VP40853570 - 14.08.11 8122 3,259.81
14108/2011 VP50433270-14.08.11 8122- 28,781.07
Are the numbers always at the end of the line? If so:
\s([0-9]+\,?[0-9]+\.[0-9]+)$
http://rubular.com/r/8z7r8epLk9
That is actually very easy:
resultString = Regex.Match(subjectString, #"([\d.,]+)\s*$").Groups[1].Value;
Provided you care only for the last number of the string. If you apply the above in each line you will get your currency. No need for special format or anything. Implementation is .NET but you can change it to anything you want.
Related
This question already has answers here:
Match exact string
(3 answers)
Closed 3 years ago.
all.
I'm querying a Postgres 9.3 database looking for a specific pattern in a field:
SELECT
P.id, P.processo_id, PR.num_formated
FROM
publications P
INNER JOIN processos PR ON PR.id=P.processo_id
WHERE
--The first numeric sequence must be exact 4 digits length, so the initial \d{4}
PR.num_formated ~ '\d{4}[\.\-\\]\d{2}\.\d{4}\.\d{1}\.\d{2}\.\d{4}'
AND
P.id=781291700 --Just to force a specific record
where PR.num_formated is defined as "character varying(255)". After being executed, the query returns:
P.id P.processo_id PR.num_formated
781291700 502707245 20190001418-14.1998.8.05.0103
My question is: Why is Postgres "ignoring" the first \d? Is there any specificity in the form it interprets the regular expressions that differ from the "traditional/regular/orthodox/whatever" way, since the same regex works perfectly in another part of my system, but using a ruby code?
Thanks in advance
Walid
The first 7 chars are ignored because the query finds the pattern as a part of the string. If you want to match the whole string use ^ and $ constraints.
'^\d{4}[\.\-\\]\d{2}\.\d{4}\.\d{1}\.\d{2}\.\d{4}$'
This question already has answers here:
How can I match "anything up until this sequence of characters" in a regular expression?
(15 answers)
Closed 3 years ago.
I have strings that are concatenations of airline codes/flightnumbers, separated with ;. The airline code and flight number are either separated by a space or -. So some examples are:
AA-1234;UA 243;EK 23;
9W 23;B6-134
Now I want to grab the airline codes from this.
I came up with the following regex: [a-zA-Z0-9]{2}[ -]. This works to grab the airline codes but also includes the airlinecode-flightnumber separator. How would I adjust my regex to not include this?
[a-zA-Z0-9]{2}(?=[ -])
See it in action here
This question already has answers here:
how can I exctract attribute value using JAVA regex
(2 answers)
Closed 4 years ago.
I have a string.
String str= " <decision CCDBNUM=\"1111111\" adddate=\"20180112\"><decision CCDBNUM=\"2222222\" adddate=\"20180114\"> ";
I want to write a regex to fetch a particular value from this string.
My Expected Output is: to fetch only the value of CCDBNUM, i.e,
1111111 2222222
Please help me with this issue.
This should work:
CCDBNUM="([^"]+)"
Just get group 1 of each match.
I assume that CCDBNUM wouldn't contain the characters CCDBNUM. If that's not the case, I suggest you use an XML parser. Regex is not enough for that.
Demo
This question already has answers here:
Getting the text that follows after the regex match
(5 answers)
Closed 4 years ago.
I have a line containing
[India,sn_GB] Welcome : { Name:{Customer1},Place:{Mumbai},}
I want to print the entire line after sn_GB] in splunk, which is
Welcome : { Name:{Customer1},Place:{Mumbai},}
I used the below regular expression:
(?<=sn_).*?$
But it prints, along with GB] like GB] Welcome : { Name:{Customer1},Place:{Mumbai},}.
In the word sn_GB, sn_ is constant and the rest two letter will vary, like GB, LB, KB, TB as such.
Please help me in correcting the regular expression.
Thanks
This will give the correct result in case sn_GB is constant.
(?<=sn_GB).*?$
If GB is not constant you can go for:
(?<=sn_...).*?$
I understand your question now.
Country codes are always 2 letters.
i'd use
(?<=sn_..\]\ ).*$
but you could use
(?<=sn_[A-Z]{0,5}\]\ \s*).*?$
(?<=sn_....).*$
is the simplest, as it will just grab 4 characters after, if it's always 2 letters for country code, and then a closing bracket and a space
This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 6 years ago.
I have a file that contains any of the following number format
12.456.7890
12-456-7890
123.456.7890
(123)456.7890
(123).456.7890
123-456-7890
(123)-456-7890
(123)456-7890
Is it possible to use regex substitution so that the final output number will always be on a format (123)456-7890 or (12)456-7890
Yes, it is:
s/\(?(\d\d\d)\)?[-.]?(\d\d\d)[-.]?(\d\d\d\d)/($1)$2-$3/g
I should mention that the above will also parse the following two:
123)456.7890
(123456.7890
You can do this using two substitutions:
perl -lpe 's/\D//g; s/(\d{3})(\d{3})(\d{4})/($1)$2-$3/' file
The first one removes all characters that aren't numeric. The second one inserts the desired characters between each group.
You should take into account that this approach will make a mess of any lines that aren't like the ones in your sample input. One means of protecting yourself could be something like this:
if ((#a = /\d/g ) == 10) { /* perform substitutions */ }
i.e. ensure that the number of matches on the line is 10 before proceeding.