Regex: find numbers greater than specific value (with varying decimal lengths)How do I return multiple values from a function?Peak detection in a 2D arrayRegex to replace everything except numbers and a decimal pointRegex greater than zero with 2 decimal placesReplace all elements of Python NumPy Array that are greater than some valueDecimal validation for greater than zeroMatching numbers greater than 40Regex expression to match equal or greater than 1, by increments of .5Use less than or greater than in where clause with a regex in railsRegex matching numbers greater than a decimal value
Scaling arrows.meta with tranform shape
What is the purpose of Strength, Intelligence and Dexterity in Path of Exile?
What does なんだって mean in this case? 「そういう子なんだってだけで...」
Is this position a forced win for Black after move 14?
Can two aircraft stay on the same runway at the same time?
Why is there no Disney logo in MCU movies?
Why did Starhopper's exhaust plume become brighter just before landing?
Generic Extension Method To Count Descendants
How do I portray irrational anger in first person?
How can weighted averages be calculated for a Dataset summarized with GroupBy
How did medieval manors handle population growth? Was there room for more fields to be ploughed?
Pen test results for web application include a file from a forbidden directory that is not even used or referenced
Why is there not a willingness from the world to step in between Pakistan and India?
Defending Castle from Zombies
How can I fix cracks between the bathtub and the wall surround?
How could a self contained organic body propel itself in space
What caused the end of cybernetic implants?
I feel cheated by my new employer, does this sound right?
Do multi-engine jets need all engines with equal age to reduce asymmetry in thrust and fuel consumption arising out of deterioration?
Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?
Why do IR remotes influence AM radios?
Why haven't the British protested Brexit as ardently like Hong Kongers protest?
How do you say "half the time …, the other half …" in German?
What is Soda Fountain Etiquette?
Regex: find numbers greater than specific value (with varying decimal lengths)
How do I return multiple values from a function?Peak detection in a 2D arrayRegex to replace everything except numbers and a decimal pointRegex greater than zero with 2 decimal placesReplace all elements of Python NumPy Array that are greater than some valueDecimal validation for greater than zeroMatching numbers greater than 40Regex expression to match equal or greater than 1, by increments of .5Use less than or greater than in where clause with a regex in railsRegex matching numbers greater than a decimal value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.
My current code works somewhat but is unwieldy - any advice much appreciated:
^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$
Thank you.
python regex
add a comment |
I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.
My current code works somewhat but is unwieldy - any advice much appreciated:
^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$
Thank you.
python regex
1
I see your regex the same as^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12
add a comment |
I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.
My current code works somewhat but is unwieldy - any advice much appreciated:
^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$
Thank you.
python regex
I am trying to regex find all values in a list that are greater than or equal to .03. The tricky part is that my values have between 9 and 15 decimal places.
My current code works somewhat but is unwieldy - any advice much appreciated:
^(?:0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|0?.[0-9][3-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])$
Thank you.
python regex
python regex
asked Mar 27 at 22:05
user3682157user3682157
5032 gold badges19 silver badges38 bronze badges
5032 gold badges19 silver badges38 bronze badges
1
I see your regex the same as^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12
add a comment |
1
I see your regex the same as^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12
1
1
I see your regex the same as
^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12
I see your regex the same as
^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12
add a comment |
3 Answers
3
active
oldest
votes
You can use an asterisk to denote zero or more of a digit:
^(?:0?.d[3-9]d*)$
This has the added benefit of matching exactly 0.03
or something with (say) 100 decimal places.
If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:
^(?:0?.d[3-9]d9,15)$
Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because.d[3-9]
is not optional, so it won't match0.1
because that string fails the[3-9]
character.
– ggorlen
Mar 27 at 22:25
add a comment |
You should simply parse your data as float
:
From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$"
so essentially you have:
t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""
Simply split into lines and check each line as float
# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)
Output:
Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad
add a comment |
Here you go: 0.030000000 - 0.999999999999999
Greater than or equal to .03 and less than 1.0
at 9-15 decimal places
0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)
Expanded
# 0.030000000 - 0.999999999999999
0?
.
(?:
03 d7,13
| 0 [4-9] d7,13
| [1-9] d8,14
)
Note - this was machine generated, there could be some overlap.
Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387195%2fregex-find-numbers-greater-than-specific-value-with-varying-decimal-lengths%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use an asterisk to denote zero or more of a digit:
^(?:0?.d[3-9]d*)$
This has the added benefit of matching exactly 0.03
or something with (say) 100 decimal places.
If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:
^(?:0?.d[3-9]d9,15)$
Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because.d[3-9]
is not optional, so it won't match0.1
because that string fails the[3-9]
character.
– ggorlen
Mar 27 at 22:25
add a comment |
You can use an asterisk to denote zero or more of a digit:
^(?:0?.d[3-9]d*)$
This has the added benefit of matching exactly 0.03
or something with (say) 100 decimal places.
If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:
^(?:0?.d[3-9]d9,15)$
Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because.d[3-9]
is not optional, so it won't match0.1
because that string fails the[3-9]
character.
– ggorlen
Mar 27 at 22:25
add a comment |
You can use an asterisk to denote zero or more of a digit:
^(?:0?.d[3-9]d*)$
This has the added benefit of matching exactly 0.03
or something with (say) 100 decimal places.
If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:
^(?:0?.d[3-9]d9,15)$
Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.
You can use an asterisk to denote zero or more of a digit:
^(?:0?.d[3-9]d*)$
This has the added benefit of matching exactly 0.03
or something with (say) 100 decimal places.
If you want to be strict about the decimal places, you can use brace syntax, which matches any repetitions between 9 and 15 digits:
^(?:0?.d[3-9]d9,15)$
Note that, as written, this regex doesn't match anything greater than or equal to 0.03--it matches anything greater than or equal to 0.03 and less than 1, and it doesn't match, say, 0.1, which is greater than 0.03. To match anything greater than 0.03, best to skip regex entirely and parse the number.
answered Mar 27 at 22:15
ggorlenggorlen
11.8k4 gold badges13 silver badges30 bronze badges
11.8k4 gold badges13 silver badges30 bronze badges
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because.d[3-9]
is not optional, so it won't match0.1
because that string fails the[3-9]
character.
– ggorlen
Mar 27 at 22:25
add a comment |
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because.d[3-9]
is not optional, so it won't match0.1
because that string fails the[3-9]
character.
– ggorlen
Mar 27 at 22:25
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
thank you for your response! Apologies, but I am confused at the last sentence - why would it not match .01 if it matches everything greater than .03 and less than 1?
– user3682157
Mar 27 at 22:23
Because
.d[3-9]
is not optional, so it won't match 0.1
because that string fails the [3-9]
character.– ggorlen
Mar 27 at 22:25
Because
.d[3-9]
is not optional, so it won't match 0.1
because that string fails the [3-9]
character.– ggorlen
Mar 27 at 22:25
add a comment |
You should simply parse your data as float
:
From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$"
so essentially you have:
t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""
Simply split into lines and check each line as float
# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)
Output:
Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad
add a comment |
You should simply parse your data as float
:
From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$"
so essentially you have:
t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""
Simply split into lines and check each line as float
# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)
Output:
Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad
add a comment |
You should simply parse your data as float
:
From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$"
so essentially you have:
t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""
Simply split into lines and check each line as float
# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)
Output:
Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad
You should simply parse your data as float
:
From your pattern you seem to have the numbers already seperated very well - why use regex at all? You numbers fill the whole line or aren't matched at all ( r"^........$"
so essentially you have:
t = """0.0000002
0.4
0.04
0.004
24544.23354
Also Bad"""
Simply split into lines and check each line as float
# splits the string into a list of lines
for line in (x.strip() for x in t.split("n")):
try:
if float(line) >= 0.03:
print(line)
else:
print("Not ok:",line)
except:
print("Not ok:",line)
Output:
Not ok: 0.0000002
0.4
0.04
Not ok: 0.004
24544.23354
Not ok: Also Bad
answered Mar 27 at 22:17
Patrick ArtnerPatrick Artner
29.7k6 gold badges26 silver badges45 bronze badges
29.7k6 gold badges26 silver badges45 bronze badges
add a comment |
add a comment |
Here you go: 0.030000000 - 0.999999999999999
Greater than or equal to .03 and less than 1.0
at 9-15 decimal places
0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)
Expanded
# 0.030000000 - 0.999999999999999
0?
.
(?:
03 d7,13
| 0 [4-9] d7,13
| [1-9] d8,14
)
Note - this was machine generated, there could be some overlap.
Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)
add a comment |
Here you go: 0.030000000 - 0.999999999999999
Greater than or equal to .03 and less than 1.0
at 9-15 decimal places
0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)
Expanded
# 0.030000000 - 0.999999999999999
0?
.
(?:
03 d7,13
| 0 [4-9] d7,13
| [1-9] d8,14
)
Note - this was machine generated, there could be some overlap.
Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)
add a comment |
Here you go: 0.030000000 - 0.999999999999999
Greater than or equal to .03 and less than 1.0
at 9-15 decimal places
0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)
Expanded
# 0.030000000 - 0.999999999999999
0?
.
(?:
03 d7,13
| 0 [4-9] d7,13
| [1-9] d8,14
)
Note - this was machine generated, there could be some overlap.
Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)
Here you go: 0.030000000 - 0.999999999999999
Greater than or equal to .03 and less than 1.0
at 9-15 decimal places
0?.(?:03d7,13|0[4-9]d7,13|[1-9]d8,14)
Expanded
# 0.030000000 - 0.999999999999999
0?
.
(?:
03 d7,13
| 0 [4-9] d7,13
| [1-9] d8,14
)
Note - this was machine generated, there could be some overlap.
Example: 0?.(?:0[3-9]d7,13|[1-9]d8,14)
edited Mar 27 at 23:44
answered Mar 27 at 23:38
slnsln
31.3k3 gold badges17 silver badges45 bronze badges
31.3k3 gold badges17 silver badges45 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387195%2fregex-find-numbers-greater-than-specific-value-with-varying-decimal-lengths%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I see your regex the same as
^0?.[0-9][3-9]d9,11$
– revo
Mar 27 at 22:12