Regular Expression for any decimal - regex

I am having a hard time figuring out a regular expression that would evalute as follows:
(valid)
.123456
1.
1.123456
123456.1
(not valid)
123
0...
I tried the following tool but I am not having much luck. (https://www.regex101.com/)
Thank you!

You could use positive lookahead assertion based regex like below.
^(?=.*\d)\d*\.\d*$
OR
^(?:\d*\.\d+|\d+\.)$
DEMO

^(?!\.$)\d*\.\d*$
Try this.See demo.
https://regex101.com/r/vN3sH3/7

Related

regex expression to find words with 0

Please provide a regex expression to find words with 0 like 'A0lytics', 'Alter0tive Medicine'.
But, it should not match words like 'Enterprise 2.0'
If you have this list of words: ["A0lytics", "0tics", "Alter0tive Medicine", "Enterprise 2.0"]
\w+0\w+ will capture "A0lytics" and "Alter0tive" (not "Alter0tive Medicine")
^[A-Za-z][A-Za-z0]+(?: +[A-Za-z][A-Za-z0]+)*$ will match "A0lytics" and "Alter0tive Medicine"
(?<!\.)([a-zA-Z]*)0([a-zA-Z]*) will match "A0lytics", "0tics" and "Alter0tive Medicine" (if you can use the negative lookbehind).
Good luck.
You can use:
^[A-Za-z][A-Za-z0]+(?: +[A-Za-z][A-Za-z0]+)*$
Demo: https://regex101.com/r/gJ5ugU/2
\w+0\w+
is it useful?
You can test online regular expressions with this.

Regex Pattern to extract url links from two string

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

Regular expression to validate time but exclude 0:00

I'm not an expert to regular expressions, but I tried to validate the user input for a time field with it.
My current regex: /^([0-9]|0[0-9]):[0-5][0-9]$/
It should validate anything positive between 0:01 and 9:59, but it also give positive return to 0:00.
Can you please help me to modify my regular expression to exclude 0:00?
Thanks a lot!
Here is the regex you are looking for.
^((?!(0:00)|(00:00)$)0?[0-9]:[0-5][0-9])$
Uses the concept of negative look ahead. Using negative lookahead, you can say match everything except 0:00 and 00:00.
Hope this helps!
You could use a negative lookahead:
^(?!0?0:00$)0?[0-9]:[0-5][0-9]$

regex 1-9999 for form validation

I am trying to write some form validation, I need one of the inputs to be 1-9999. I know nothing about regular expressions ( never used them before) and here is my first attempt
/^([1-9][1-9]|[1-9]|[1-9]\d|9999)$/
Does not seem to want to work, can anyone help me? Thanks!
Try the below regex,
^(?:[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[1-9])$
DEMO
This doesn't exclude zero, but /^\d{1,4}$/ should do the trick.
Try using this
^([1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9])$
To exclude zero values but include non-zero ones with leading zeros:
([1-9]\d{0,3})|(\d[1-9])\d{0,2}|(\d{2}[1-9])\d?|(\d{1,3}[1-9])
This Regex should not match numbers that start with 0 a part from 0
Regex: /^(?!(0\d))\d{1,4}$/
Regex (Exclude Zero): /^(?!(0))\d{1,4}$/
Test: https://regex101.com/r/zfCKel/2

How can I build the regex to match a string NOT containing "au=1"?

As the title says... :)
Could you help me to build a regex to match a strings NOT containing "au=1"?
I was playing with negative lookahead with no luck but I'm quite sure that I should get something using that.
Thanks!
Using negative lookbehind:
?<!au=1
Negative lookahead will only look ahead, making the regex match match against au=1match. You should read up on the differences in more detail here.
You can also just match against au=1 and negate the result:
if(!Regex.IsMatch(input, #"au=1"))
{
// blah blah blah
}
Prefix the pattern with ! to negate it:
!au=1
I finally did it with this regexp
^(?!.*au=1).*$