Looking for a regex in C++ that would add integers and fractions on their own to the regex iterator.
So say we have the current string given
12, 144, 18, 12/13, 92, a, 34, 8, 52
I'm looking to have 12 144 12/13 all added, without the comma or 12 added twice (or 13)
Currently have \d+?/\d+|\d+[^/]
however this also grabs anything after an integer (i.e. the comma)
What am I missing here to make sure I grab the int and not the comma whilst making sure I don't grab numbers from fractions twice?
Related
I am trying to build a regex for following rules
No characters – only numbers are allowed to enter
Numbers must contain not less than 8 digits
Numbers and combinations, starting as follows should not be allowed:
[3.1] - Any number starting with 0 (zero) and with 1 (one);
[3.2] - Numbers starting with 20, 21, 22, 23, 24, 25, 26, and 27.
I am able to achieve regex for points 1, 2 and 3.1 like this
^[2-9]{1}[0-9]{7,}$
But I am not able to find solution for point 3.2
This is one of the options I started with, this regex matches the string that must start with 20, 21, 22, 23, 24, 25, 26, or 27.
^([2][0-7])[2-9]{1}[0-9]{7,}$
I just have to find the negation of this first condition.
Please help!
Rather than trying to negate the 20-27 condition, just match numbers that start with 28 or 29 instead:
^(?:2[89]|[3-9]\d)\d{6,}$
Demo on regex101
I need a regular expression for a string like this:
ex. 1234-1234-12345
where the first two numbers must be between 01-18 and the whole string must be 15 characters long
example: 0511-xxxx-xxxxx.
I tried using [RegularExpression(#"^[0-9]{1,18}$",
ErrorMessage = "Invalid Id.")]
but it doesnt work, it even gives me an error that says ',' is missing.
Lets make it even easier, a numeric string 13 character long where the first two digits must be between 01-18.
Ex. 1234567890123
(I would prefer the first format but this one work too).
I don't know how to use Regex so if someone can kindly give me a link to somewhere I can learn I would very much appreciate it.
And, most importantly, if there is a better way to get around this without using Regex I would appreciate it as well.
Apparently, my request is a little unclear. What I want it that the first two digits (XXxx-xxxx-xxxxx) be 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18.
Your "first two numbers" is a little unclear, but how about:
var pattern = #"(0\d|1[0-8])\d\d-\d{4}-\d{5}";
If you want to match the whole string and not just find the substring, you need
var pattern = #"^(0\d|1[0-8])\d\d-\d{4}-\d{5}$";
If you didn't have the groups separated by hyphens, use:
var pattern = #"^(0\d|1[0-8])\d{11}$";
You can use it like
Regex.IsMatch(aString, pattern)
We have to find out all the numbers consisting of 3 and 5 only in a given range L and R(inclusive).
What are the possible approaches to do this task?
Given that,
1 <= L <= R <= 10^9.
The obvious approach would be to synthesize numbers systematically until you produced one larger than the specified maximum.
In this case, you'd produce something like: 3, 5, 33, 35, 53, 55, 333, 335, 353, 355, etc. until you get to one larger than 109.
Hint: since you only have two possible digits, you could think of this as counting in binary, but convert each number using 3 in place of 0 and 5 in place of 1 (then compare the result to 109 to see if you're done yet).
I am applying below Mask setting to Devexpress TextEdit control but on executing give me syntax error.
textEdit1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
textEdit1.Properties.Mask.EditMask = "(100(?:\\.0{1,3})?|0*?\\.\\d{1,3}|\\d{1,2}(?:\\.\\d{1,3})?)%";
Concept behind using this regular expression is to input value from 0-100 percentage with 3 decimal optional.
like 25, 25.5, 60, 60.369, 99 but 101, 10.2569 is invalid values.
Please guide me how can i correct this expression.
Try the following (I don't have access to devexpress here so could not test fully):
(100(\R.0{1,3})?)|((\d{1,2}(\R.\d{1,3})?))
It is in two alternate parts separated with the "|", the first part checks for 100 with up to three decimal zero (100, 100.0, 100.00, 100.000)
The second part deals with numbers with one or two digits before the decimal and optionally a decimal and up to three digits after (25, 25.5, 60, 60.369, 99).
The \R. actually Matches the decimal separator specified by the System.Globalization.NumberFormatInfo.NumberDecimalSeparator property of the current culture. per the documentation. If you just want to pick up decimal regardless you can change \R. to \.
I'm trying to write a simple regex but I don't know why it is not working.
User enter 2 digits number like 01, 09, 23, 55, until 82. After 82 system will refuse.
Here is my regex, 2 digits must be smaller than 82.
0[1-9]|[1-8][0-9]|8[0-2]
You should have [1-7] for the range 10-79, not [1-8]. Don't forget the ^ and $ to specify the start and ending of the string:
^(0[1-9]|[1-7]\d|8[0-2])$
Why not cast to an integer and then just test x < 82?
Your second part is wrong. It'll match from 10 to 89, whereas you want it to match from 10 to 79 and let the third part handle 80 to 82.
0[1-9]|[1-7][0-9]|8[0-2]