I need a regex that allows values between 0,01 and 9.999.999.999.999,99. Any suggestions?
I am using the following regex:
"(?:(?:[0-9]\\d{0,2})(?:\\.\\d{3})*(?:,\\d{2})|0,(?:[0-9]\\d|0[0-9]))"
But it allows 0,00
Thank you for your help
If all you're wanting to do is validate then this regex should work for you.
(?:(?!(?:0{1,3}\.){0,}0{1,3},00)(?:\d{1,3}\.){0,}\d?\d?(?:(0)|\d),\d(?(1)[1-9]|\d))
Regex Demo
I've updated it so that if the value is 0,00 it will not match, but it'll match 10.000,00 or 1,00
The regex will match:
10.000,00
1,00
0,01
10,00
9.999.999.999.999,99
The regex will not match:
0,00
0.000,00
0,01 - 0,99 is a particular case. So is 9.999.999.999.999,99. I would do:
(0,((\d[1-9])|([1-9]\d)))|((([1-9]\d{0,2}(\.\d{3}){0,3})|([1-9](\.\d{3}){4})),\d{2})
Edit
As pointed out by Biffen, 0,x0 is also a special case
I'm not sure regex would be the most appropriate tool for this job here, however I think this is what you are looking for.
(?=[\d\.]*[1-9][\d\.]*,\d{2}|[\d\.]*,[\d\.]*[1-9][\d\.]*)(\d{1,3}\.)*\d{0,3},\d{2}
the positive lookahead enforces the non-zero value
(?=[\d\.]*[1-9][\d\.]*,\d{2}|[\d\.]*,[\d\.]*[1-9][\d\.]*)
and the rest just matches the pattern
(\d{1,3}\.)*\d{0,3},\d{2}
http://regexr.com/39ujm
Related
What I want to do is select everything except [0-9]{4,7}. I know negative lookaheads so I tried this: (?![0-9]{4,7}) but the result was strange. Any ideas to get this?
For example,
Sample text for my question!
2020 0316 or 200316
fdsa2020asdf
Desired
Sample text for my question!
or
fdsaasdf
This matches the desired parts of all your test cases:
\D{2,}
See live demo.
I added {2,} only to avoid matching the space between 2020 and 0316. If you're ok with matching that, you can remove {2,}.
I have two string in which I have to sorten urls. I want a regex pattern to extract them
https://l.facebook.com/l.php?u=http%3A%2F%2Febay.to%2F2EyH7Nq&h=ATNHM5kACc4rh_z68Ytw__cNCzJ63_iPezd_whc0PjcsN4qj1PfdJgFXyrOKM3-biqPm7eAXTOc5LD6r-7JXhRsqsqEHUs0jaJkjvm_QWf6sqbHQmS63q6P0_NcQoUa86Az5EttNT9xJb_evKBaiFxW7e7v2afJQn2zNxz5lQ8xgxhMcEFuJ3hUiSYUMEemKFB2LSIgAZFibRv4GeRrTk8hxFaArkBuAhQaXQFd4jX-aQuUYhjD0ErV5FY-D4gFMpb0lFCU7SyBlRpkUuOcHVjwjxN-_g6reMYwo8loAJnJD
/redirect?q=http%3A%2F%2Fgoo.gl%2FIW7ct&redir_token=PV5sR8F7GuXT9PgPO_nkBFLABQx8MTUxNjA3OTY5MEAxNTE1OTkzMjkw&v=7wmIyD1fM4M&event=video_description
Output will be from 1st and 2nd link:-
http%3A%2F%2Febay.to%2F2EyH7Nq
http%3A%2F%2Fgoo.gl%2FIW7ct
Please help me out.
I have already used:-
(http|https).*?&
but its not working on first url.
You can try this:
=(https?[^&]*)
Demo
If lookbehind is possible in your flavour of regex then you may try this as well which will ensure to not capture the equal sign:
(?<=)(https?[^&]*)
Demo 2
Try this regex !
I am also attach the output of the regex through regex101.
http%3A%2F%2F(.*)%2F(.*[^&])(?=&)
You can use this pattern to only capture goo.gl and ebay.to links:
(http%3A%2F%2F(ebay\.to|goo\.gl)%2F[^&]*)&
Demo
i have the folwing problem in regex
i want to get just the string from that pattern of regex
#10 12:00:00 - some text
#100 11:04:00 ! some text
#2 23:01:10 ? some text
this is pretty easy and the answer to that in regex will be
#[0-9]+ [0-9]{2}:[0-9]{2}:[0-9]{2} [-,!,?].*
but it gets much more complicated if I want to filter as well all the inputs i get with the time 00:00:00.
it is possible but it's really ugly is there any megical beautiful way to do this with a simple regex
You could use a negative lookahead (?!00:00:00) in the regex at the start
(?!00:00:00) fails when it matches the regex inside
https://www.regular-expressions.info/lookaround.html
,Ray Balwierczak,4/11/2017,,895 Forest Hill Rd,Apalachin,NY,13732,y,,
i want to select only 13732 from the line. I came up with this regex
(\d)(\s*\d+)*(\,y,,)
But its also selecting the ,y,, .if i remove it that part from regex, the regex also gets valid for the date. please help me on this.
Generally, if you want to match something without capturing it, use zero-length lookaround (lookahead or lookbehind). In your case, you can use lookahead:
(\d)(\s*\d+)*(?=\,y,,)
The syntax (?=<stuff>) means "followed by <stuff>, without matching it".
More information on lookarounds can be found in this tutorial.
Regex: \D*(\d{5})\D*
Explanation: match 5 digits surrounded by zero or more non-digits on both sides. Then you can extract group containing the match.
Here's code in python:
import re
string = ",Ray Balwierczak,4/11/2017,,895 Forest Hill Rd,Apalachin,NY,13732,y,,"
search = re.search("\D*(\d{5})\D*", string)
print search.group(1)
Output:
13732
I am looking for a reg ex to parse codes that look like this:
TEDL 9V1J 5K1Y EQFF NSA1 CF4T 8NQU UZL1
I have this regex, which works, but I would be grateful to understand how to make it more concise.
[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}
Thanks.
Add this \s[A-Z0-9]{4} regex into a non-capturing group and add {7} after that to make the pattern to repeat for exactly 7 times.
^[A-Z0-9]{4}(?:\s[A-Z0-9]{4}){7}$
OR
\b[A-Z0-9]{4}(?:\s[A-Z0-9]{4}){7}\b
DEMO
You can use refactory your regex to:
\b((?:[A-Z0-9]{4}(?: |$)){8})
RegEx Demo
(([A-Z0-9]{4})\s){7}([A-Z0-9]{4})