regular expression for amount enclosed [closed] - regex

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
This regular expression
/^\d{1,6}(?:\.\d{0,2})?$/
limits the user to only 6 digits.
How to make this regex work to allow any number of digits(no max limit)
How to make this regex optional

Assuming you just mean any number of digits followed by any single character followed by 2 digits, then use:
/^\d+(?:.\d{0,2})?$/
If 0 is ok, then:
/^\d*(?:.\d{0,2})?$/
I think you actually are trying to find money values (dollar and cents) which would likely be this instead:
/^\d*(?:\.\d{0,2})?$/

Your regex limits it to 1-6 digits, followed by an optional 0-2 decimals.
To remove the limit, remove the {1,6} and replace with + and to make it optional, wrap in (...)?:
/(^\d+(?:\.\d{0,2})?$)?/
This make the input, if provided, still require at least 1 digit before the decimal place.

To make the first part match one or more digits, you can change it to /^\d+(?:.\d{0,2})?$/.
It's a bit confusing what you mean by 'optional', so I'm not sure what to suggest there.

Related

Regex that does not repeat the same character 2 times in a row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to make a regex to validate an amount in which it only accepts numbers, points (.) Optional, 1 comma (,) optional and that after the comma I have at least 2 more numbers, the farthest I've come is this
^(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
This works fairly well, the problem is that it allows me to put the period (.) Followed more than once for example (100 ... 000), this accepts it, but I need it to only accept one period (.) At a time, how do i fix it?
I need the regex to validate as follows
100 VALID
100.000,00 VALID
100. INVALID
100..00 INVALID
100, INVALID
100..000,00 INVALID
To prevent the same character (in this case a dot) appearing consecutively, use a negative look ahead anchored to start of input:
^(?!.*[.][.])<rest of regex>
In your case:
^(?!.*[.][.])(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
See live demo with test cases from question.
I'm not clear on what you actually want to match, but I don't need to understand that to answer your question, which was how to prevent the same character appearing consecutively.

Regex - how to negate a group of substring in a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to create a numeric pattern of 4 digits such that there is at least one non-zero number.
So, it can be "1234", "0001" but not "0000". Also, we must not use the lookahead operator and the lookbehind operator.
my current pattern [0-9]{4}. I can't seem to understand how to remove just "0000".
It's in fact very easy. You will need to specify the following:
four digits, from which the first is not 0
OR
four digits, from which the second is not 0
OR
four digits, from which the third is not 0
OR
four digits, from which the fourth is not 0
Disjunction regex
Use the | operator.
Digit
[0-9]
Non-zero digit
[1-9]
Summary
In this answer you find everything you need. Since this is homework, I will let you work out the formula. Happy thinking!
As per Lajos's suggestion
^[1-9][\d]{3}|^[\d][1-9][\d]{2}|^[\d]{2}[1-9]\d|[\d]{3}[1-9]

Regex: check if string corresponding Word numbering list style [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm looking for regex-way to find if a string matches any of this pattern:
2.
1.2
3.4.5
These numbers are taken from the numbering list of Word.
If you only want to match what is above, use ^((\d\.)+\d|(\d\.))$. (Link to regex tester).
This will either match that first kind of pattern (with a digit and then a period) or the other two, which have a digit followed by a period more than 1 time, and another digit at the end.
If you also want to match patterns like 3.4., i.e., strings that may or may not end in a period, you can use ^(\d\.)+\d?$ (Link)
This matches patterns that have a digit followed by a period one or more times, and then maybe a digit after that.

Date Range Regex in Notepad++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Looking for a regular expression in Notepad++ to find any years outside of the year range: 1980-2019
This will find WITHIN the year range I'm looking for, but I can't find outside of the range.
[1-9]\d{4,}|19[8,9][0-9]|[1-9]\d{4,}|20[0,1][0-9]
Any help is greatly appreciated!
I don't particularly think regex is suitable for this, but this might work:
(?![1-9]\d{4,}|19[8,9][0-9]|[1-9]\d{4,}|20[0,1][0-9])\b\d+
I simply negated your regex with a negative lookahead, and matched the digits with \d+. This will match any number of digits, because technically the year 1 is also outside of the range 1980-2019. If you only want 4 digit years, simply change + to {4}.

Regex needed for this string in powershell [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need a regex which can search in the below string
Version updated to 13.0.1700.943 by the build system. NO_CI
Output needed 13.0.1700.943
Use this regex
(\d+\.){3}\d+
Breakdown
(\d+\.): This is the first capturing group. It finds one or more digits followed by a dot. Note that in regex, this dot has to be escaped.
{3}: This quantifier means, it will match the previous expression three times. In your example, you had three such instances
\d+: The last number does not have a dot after it, so we write it after the previous group.
Just to add to Richard Hamiltons answer (which would also match an IPv4)
the quantifier's can also limit the number of required places to match exactly your example
\d{2}\.\d\.\d{4}\.\d{3}
For a range you can use \d{1,2} to match one or two digits.