#### Regular expression for a range of numbers from 0.5 to infinity

In regular expressions, there are no ready-made templates for ranges of numbers, especially for fractional ones. Because regulars are primarily text processing. Regulars are able to work only with individual digits, not numbers. But numbers are a text consisting of numbers written in a certain pattern. That is, you need to separate the numbers — these are signs 0-9 and numbers — compound "words" from these signs.

## Divide into subtasks

Let's think about the task. Our big task actually consists of two smaller ones:

- Numbers from 0.5 inclusive to 1, not including it in the range.
- Numbers from 1 to ∞ inclusive.

Let's write regular expressions for each case separately.

### Numbers from 0.5 and more, but less than 1

Let's try to write down in words what we want to get.

Numbers in the range [0.5, 1):

**Be sure**to start with the digit 0.**There must be**a dot or comma after zero.**There must be**a number from 5 to 9 inclusive.- Optionally, there may be additional digits after.

**^0[.,][5-9]\ d{0,}?$** — it turned out to be such a regular:

**^**— the beginning of the line (not to look for values in any part of the text).**0**is actually zero.**[.,]**— any of the characters in parentheses, in this case either a comma or a period.**[5-9]**— one digit from 5 to 9 inclusive.**\d{0,}?**is any digit;**{0,}?**— lazily repeated 0 or more times.**$**— the end of the line (not to look for values in any part of the text).

### Numbers from 1 to ∞ inclusive

Let's try to write down in words what we want to get.

- The number must
**necessarily**start with a digit from 1-9, because numbers less than 1 are not suitable for us. - Optionally, there can be any additional digits after.
- There may not necessarily be a "tail" in the form of a fraction.

**^[1-9]\d{0,}?([.,]\ d{1,}?){0,1}$** — it turned out such a regular:

**^**— the beginning of the line (so as not to pick out values in any part of the text).**[1-9]**— digit from 1 to 9 inclusive.**\d{0,}?**— any digit;**{0,}?**— lazily repeated 0 or more times.**([.,]\d{1,}?){0,1} — [.,]**— a dot or comma followed by**\d{1,}?**one or more digits lazily repeated. The expression was wrapped in parentheses in order to set the whole rule**{0,1}**— zero or one time for it.**$**— the end of the line (not to look for values in any part of the text).

## All together

The simplest thing left is to combine several regular expressions into one. It's quite simple, you need to wrap each expression in a separate group using parentheses **(expression**), and then put a sign **OR — |** between the expressions. You’ll get **(expression 1)|(expression 2)**.

The result: **(^0[.,][5-9]\ d{0,}?$)|(^[1-9]\d{0,}?([.,]\d{1,}?){0,1}$)**

## Notes

Some parts of the expression can be changed for the convenience of writing, reading or perception:

**\d**— can be replaced by**[0-9]****{0,}**— can be replaced by*******{1,}**— can be replaced by**+**

Also, for convenience, **^** and **$** can be taken out of brackets and left in a single copy:

**^((0[.,][5-9]\d{0,}?)|([1-9]\d{0,}?([.,]\d{1,}?){0,1}))$**