^[.1-9]*\d$ allows multiple dots [duplicate] - regex

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regex for floating point?
I am trying to use the regex.
The valid strings are:
1
11
5
12222222233
1.2
.5
1222.33444
12234.456
0
Invalid Strings are
.
-2
san
2s2
S2S
ssss2ssss
25535535TY
But this regex does not qualify to test multiple dots (.)
such as
1......5,
5..2233
1223...5
This accepts these values as valid string. Please help me how to fix this issue with reg.
Note, the above validation should be passed.

How about that regex: \d*(\.\d+)?
EDIT
This regex \d*(\.\d+)? will allow empty values too.
The updated version: \d*(\.)?\d+ does not have that issue.
Please note that negative values will not be allowed as \d matches only digits 0..9

^\d*\.?\d*$ should do the trick, but a little thinking and reading more about regex would have told you the same.
Didn't see that . alone or . at the end is not allowed. So ^\d*(\.\d+)?$ sould be just fine

Related

Postgresql regex replace numbers to asterisks [duplicate]

This question already has answers here:
Regex to mask characters except first two and last two characters in Java
(4 answers)
Closed 5 months ago.
I use Postgresql and need to replace numbers to asterisk at database layer. Howerver I'm new to learn regex and seems to be hard to do this with my current knowledge.
I will have in my database 16 numbers varchar and I need to replace middle numbers with asterisk.
Example.
123467812345678 -> 12**********5678
Could someone tell me how regex for this should look like in postgresql ?
Thanks in advance
Thanks to #Wiktor Stribiżew:
SELECT regexp_replace('123467812345678', '(?<=..).(?=....)', '*','g');

Regex for text between items [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I'm having a hard time pulling out just the 1069 value using regex. I think I might be trying to use unsupported features to make it worse.
Q1: Would someone be able to let me know what regex would be needed to pull the numbers the 4th and 5th colons (value of 1069)
Q2: How to pull the items after the 6th colon? (value of 2929)
sample text:
diamond:dev:liquid:beta:1069:zone:2929
Answer 1: How to get value between 4th and 5th colons:
(?>[^:]+:){4}([^:]+)
Try at regex101
Answer 2: How to get value after the 6th colon:
(?>[^:]+:){6}([^:]+)
Try at regex101
Note: You can replace + with * to handle cases like ::::2: (empty between colons).

How to match a int less than 50 in regx [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 2 years ago.
I want to match a url like "index.html\index_1.html\index_12.html\index_49.html\index_n.html
and the n must <50 not be 50
You can achieve this by using - index_[1-4]?\d\.html as your regex.
What this does is it first limits the first digit of two to the numbers 1-4 then accepts any other following digit. The ? makes it so that the digit may be skipped if it cannot be found
regex101 link - https://regex101.com/r/BwMCdu/1 which has a few examples
Try the following:
(((index)|(index_[0-9])|(index_[0-4][0-9])).html)
You can use [1-4]?[0-9]
index.html\index_1.html\index_12.html\index_49.html\index_[0-4]?[0-9].html$

Regex help to filter only 720p [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 4 years ago.
I'd like to setup auto download of some Anime using an RSS feed, but only 720p versions. The format never changes and it always looks like below.
[Blahblah] Blahepisode - 12 [720p].mkv
Here is the regex I have come up with but cannot get to work properly.
/.\+[720p]+/g
Any help would be appreciated!
Assuming you have lines that look like your example, it will be mached with the following Regex:
.+(?:\[720p\].mkv)
It maches one or more chacacters at start, followed by '[720p].mkv'.
Note that the Square brackets are escaped to '\[' and '\]', otherwise they have special meaning.
if you only need '[720p]' then you can use:
\[720p\]

creating a regex that captures these rules [duplicate]

This question already has answers here:
Regex to validate password strength
(11 answers)
Closed 7 years ago.
I have the following password requirements I'm trying to express in a regex expression and I'm struggling. Any help appreciated!
Passwords must contain characters from 3 of the following 4 types:
upper case letters
lower case letters
numerals
special characters
I've found some similar examples and if my knowledge of regex was stronger I could figure it out but I haven't found one that has the "3 of 4" requirement.
Edit:
Ok here is what I'm using for now, I'm currently testing it. Does this look right?
passwordStrengthRegularExpression="(?=^[^\s]{8,}$)((?=.?\d)(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=(.\W){1,})(?=.?[a-z])|(?=(.\W){1,})(?=.?[A-Z])(?=.?[a-z])|(?=.?\d)(?=.?[A-Z])(?=(.\W){1,}))^.*"
Analog to https://stackoverflow.com/a/5142164/2606322 I would do the following for all 4 requirements
^(?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8}$
and then add the other 4 (3 of 4) possibilities or-ed together like
^
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[!##$&*])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[a-z]).{8})|
((?=.*[A-Z])(?=.*[!##$&*])(?=.*[0-9]).{8})|
$
just in one line. Ugly but might work. And, of course, replace the !##$&* with the set of your liking.