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

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

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

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

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+)*$

Regex value of 0.0-5.0 [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 5 years ago.
I'm trying to create a regex string that allows values 0.0 - 5.0. I need the one decimal point to be required. The string below gets me there, but it also allows 5.1-5.9. How do I prevent 5.1-5.9 from being entered, and allow 5.0?
^[0-5]+(\.[0-9]{1})$
Try this regex:
^([0-4]\.[0-9]|5\.0)$
It matches any number from 0 to 4 then dot then any number.
it also matches 5.0
Note: Your regex has another problem that you used + after [0-5] which also matches 55 for example, so you need to remove the +. You also need to remove {1}, It won't make any change but it's useless.

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

RegEx to get numeric value and values with range [duplicate]

This question already has answers here:
How to write regex to match number ranges?
(7 answers)
Closed 8 years ago.
I need a RegEx to match the following format:
3
7.3
5.7 (2.2-10.4)
I want to check in JS if the given value i.e. 5.7 (2.2-10.4) is valid. And in PHP I want to split the string to get all three values (if there is a given range).
That means I have to check for a simple numeric value (int and float) or a numeric value followed by a range like (d-d)
My attempt: /^(\d+)\s\((\d+)\-(\d+)\)$/
based on your attempt, does not count for negative values
^(\d+(?:\.\d+)?)(?:\s*\((\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)\))?$
Demo