I need to remove the space between the numbers using RegEx means I want to make a formated number from the input like {lhs: \"1000 U.S. dollars\",rhs: \"58 740.6015 Indian rupees\",error: \"\",icc: true} I tried the following expression Regex regex = new Regex("rhs: \\\"(\\d+.\\d*)"); but its give me a error "Input format not correct" so how can I remove the space between the numbers
P.S The currency name will change each time it called
use the following expression
string value = Regex.Replace(response.Split(',')[1], "[^.0-9]", "");
Related
I want to accomplish the following with ruby and if possible a regex:
Input: "something {\"key\":\"value\",\"key2\":3}"
Output: [["\"key\"", "\"value\""], [["\"key2\"", "3"]]
My attempt so far:
s = "something {key:\"value\",key2:3}"
s.scan(/.* {(?:([^:]+):([^,}]+),?)+}$/)
# Output: [["\"key2\"", "3"]]
For some reason the regex above only matches the last key value pair. Does someone know how to retrieve all the pairs?
Just to be clear, "something" can be any kind of string. For this reason, solutions such as (1) splitting the text directly on the equal or (2) a regex as used in s.scan(/(?:([^:]+):([^,}]+),?)/) don't work for me.
I know there are similar questions on SO. Still, from what I saw, they mostly tend towards the solutions 1 & 2 or focus on a single key value pair.
your string looks like a json data structure encoded as a string, you can use JSON.parse for this as long as you remove the word "something " from the string
require 'json'
string = "something {\"key\":\"value\",\"key2\":3}"
# the following line removes the word something
string = string[string.index("{")..-1]
x = JSON.parse(string)
puts x["key"]
puts x["key2"]
you can then convert that to an array if required
alternatively if you want to use regular expressions try
string.scan(/(?:"(\w+)":"?(\w+)"?)/)
I'm trying to get the number of tracking_number from the string.
string = '{:rate_type=>"PAYOR_ACCOUNT_PACKAGE", :rated_weight_method=>"ACTUAL", tracking_number=>"795856589804"}, :group_number=>"0", :package_rating=>{:actual_rate_type=>"PAYOR_ACCOUNT_PACKAGE", :package_rate_details=>{:rate_type=>"PAYOR_ACCOUNT_PACKAGE", :rated_weight_method=>"ACTUAL", :minimum_charge_type=>"CUSTOMER_FREIGHT_WEIGHT", :billing_weight=>{:units=>"LB", :value=>"1.0"}}'
I have tried /tracking_number=>['"]((.*?)['"])*/ but getting all the string after the match.
Can anybody help me on this.
I have tried this at https://rubular.com/r/ZcmJinTHDQSDsZ
Output I want is 795856589804
Remove * from end of your regex. This is the reason you are getting all the string after match.
And If you want to get just the number part then use this regex.
/tracking_number=>"(\d+)"/
I have two 'phone numbers listed in different formats, but want just to extract the digits only:
17347545296
(734) 754-5296
Also using REGEXREPLACE but avoids errors where "A1" is Number format and a simpler expression:
=regexreplace(A1&"","\D","")
One approach would be to use REGEXREPLACE and remove all non numeric characters:
=REGEXREPLACE(A1, "[^0-9]+", "")
If a given cell could also have digits not belonging to the actual phone number, then we would have to do more work. But the above suggestion should work for your sample data shown.
I'm using PIG to generate a list of URLs that have been recently visited. In each of the URLs, there is a string of numbers that represents the product page visited. I'm trying to use a regex_extract_all() function to extract just the string of numbers, which vary in length from 6-8. The string of digits can be found directly after jobs2/view/ and usually ends with +&cd but sometimes they may end with ).
Here are a few example URLs:
(http://a.com/search?q=cache:QD7vZRHkPQoJ:ca.xyz.com/jobs2/view/17069404+&cd=1&hl=en&ct=clnk&gl=ca)
(http://a.com/search?q=cache:G9323j2oNbAJ:ca.xyz.com/jobs2/view/5977065+&cd=1&hl=en&ct=clnk&gl=ca)
(http://a.com/search?q=cache:aNspmG11qAJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=clnk&gl=hk)
(http://a.com/search?q=cache:aNspmG11AJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=clnk&gl=hk)
(http://a.com/search?q=cache:aNspmG11qAJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=cl k&gl=hk)
Here is the current regex I am using:
J = FOREACH jpage GENERATE FLATTEN(REGEX_EXTRACT_ALL(TEXTCOLUMN, '\/view\/(\d+)\+\&')) as (output:chararray)
I have also tried other forms such as:
'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]', 'view.([0-9]+)', 'view\/([\d]+)\+',
'[0-9][0-9][0-9]+', and
'[0-9][0-9][0-9]*'; none of which work.
Can anybody assist here or have another way of going about it?
Much appreciated,
MM
Reason for"Unexpected character 'D'" is, you need to put double backslash instead of single backslash. eg just replace [\d+] to [\\d+]
Here your solution, please validate all your inputs strings
input.txt
http://a.com/search?q=cache:QD7vZRHkPQoJ:ca.xyz.com/jobs2/view/17069404+&cd=1&hl=en&ct=clnk&gl=ca
http://a.com/search?q=cache:G9323j2oNbAJ:ca.xyz.com/jobs2/view/5977065+&cd=1&hl=en&ct=clnk&gl=ca
http://a.com/search?q=cache:aNspmG11qAJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=clnk&gl=hk
http://a.com/search?q=cache:aNspmG11AJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=clnk&gl=hk
http://a.com/search?q=cache:aNspmG11qAJ:hk.xyz.com/jobs2/view/16988928+&cd=2&hl=zh-TW&ct=clk&gl=hk
http://a.com/search?q=cache:aNspmG11qAJ:hk.xyz.com/jobs2/view/16988928)=2&hl=zh-TW&ct=clk&gl=hk
http://webcache.googleusercontent.com/search?q=cache:http://my.linkedin.com/jobs2/view/9919248
Updated Pigscript:
A = LOAD 'input.txt' as line;
B = FOREACH A GENERATE REGEX_EXTRACT(line,'.*/view/(\\d+)([+|&|cd|)?]+)?',1);
dump B;
(17069404)
(5977065)
(16988928)
(16988928)
(16988928)
(16988928)
I'm not familiar with PIG, but this regex will match your target:
(?<=/jobs2/view/)\d+
By using a (non-consuming) look behind, the entire match (not just a group of the match) is your number.
I have a string like this
(THQ836721='Yes' and BRQ836716='Yes') or (BRQ836717='Yes') and (THQ836728='Yes' and BRQ836756='Yes') or (BRQ836117='Yes') and (SYSQ123='No')
I need a Reg Ex to get the numbers after THQ,BRQ and SYSQ
My string may smaller or shorter or may have any times of this THQ,BRQ or SYSQ.
So please help to form a Reg eXpression to get the numbers .
The length of numbers may vary
I am using VB.Net in VS2008
Try this expression:
(?<=THQ|BRQ|SYSQ)\d+