What's the regular expression for pipe-delimited number? [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I want to check that a String is pipe-generated numbers. There should be numbers between pipes.
Valid Strings examples: 300, 300|600.
Invalid Strings examples: 300||||600
I tried ^([\d|\d])*$. However, this still said that 300||||600 is a valid String.

Here, what you want is one number, ie \d+, followed by an undetermined number of occurrences of a pipe then a number, which would be (\|\d+)* (the pipe is escaped).
As you want it to cover the whole input this would be
^\d+(\|\d+)*$

Related

How to match all strings that has only one dot using regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to capture strings containing only one dot. String will mostly contains domain names like
test.com, fun.test.com, lesh.test.com.
I need to check only the first one and to ignore the string that has more than one dots.
How can I do this using regex?
Like this :
^[^.]+\.[^.]+$
Check explanations https://regex101.com/r/mn7Ccr/1

regex to grab int/floats and exclude text [duplicate]

This question already has answers here:
RegEx for both, integer and float [closed]
(3 answers)
Closed 4 years ago.
trying to write the appropriate regex expression to capture barometric pressure with two string possibilities. looking to simply grab the float values and remove the "in" string.
The String possibilities are (examples):
'30.01in'
or
'30in'
my current expression (see below) works for the former (30.01), but fails to grab the float in the latter (30in)
re.compile('[0-9]?[0-9]\...')
(\d+(?:\.\d+)?)in
This should capture ints or floats

Find the shortest match that matches a specific condition using regex [duplicate]

This question already has answers here:
Regular expressions: Ensuring b doesn't come between a and c
(4 answers)
Closed 4 years ago.
I'd like to find these three strings in any order and the result may have all these three strings including any character between them with the shortest length.
strings are: "ACT", "AGT" and "CGT".
Sample input: "ACTACGTTTAGTAACTCGTCT"
I tried but the regex returns the first occurrence matched which is "ACTACGTTTAGTAACTCGT"
/(ACT.*AGT.*CGT)|(ACT.*CGT.*AGT)|(AGT.*ACT.*CGT)|(AGT.*CGT.*ACT)|(CGT.*ACT.*AGT)|(CGT.*AGT.*ACT)/g
Output has to be "AGTACTCGT"
You can't return separate bits of a string already concatenated in one go.
See here: Regular expression to skip character in capture group
You can first match each bit, using parentheses to group them, and then put them together in a separate step

Validate time and allow negative values [duplicate]

This question already has answers here:
How do I include negative decimal numbers in this regular expression?
(17 answers)
Closed 6 years ago.
I use this regex to validate time entries, e.g. 08:34 - this is a valid time,
negative time e.g. -08:54 is not valid with this regEx.
Actually I don't know how to extend this regex in order to make also negative times valid:
var regex_time =/^([0-9]{2})\:([0-9]{2})$/;
You can use the regex:
^-?([01]\d|2[0-3]):([0-5]\d)$
To get a positive/negative valid 24h format. If you don't need to limit the user to 24h format, use:
^-?(\d+):([0-5]\d)$
The question mark is a quantifier that means 0 to 1 of previous item.

Regex for range 1-1000 [duplicate]

This question already has answers here:
Regular expression where part of string must be number between 0-100
(7 answers)
Closed 1 year ago.
I need help creating a simple regex for a whole number range of 1-1000, with no special characters.
The two I have both seem to break or allow characters or not the full range:
^\d(\d)?(\d)?$
^[0-9]{1,3}$
Try this:
^([1-9][0-9]{0,2}|1000)$
[1-9][0-9]{0,2} matches any number between 1–999
1000 matches 1000
Use ^(.*[^0-9]|)(1000|[1-9]\d{0,2})([^0-9].*|)$ which will match 1000 or a non-zero digit followed by up to two further digits. It will also allow other characters on either end of the number.