logo
Tags down

shadow

A regex for range of numbers in curl


By : DPRoberts
Date : July 30 2020, 12:00 PM
Hope this helps In your pattern b0+\b([1-9]|[1-9][0-9]|100)\b.png the \b in this part 0+\b is not going to work because there is no word boundary between a 0 and another digit coming from the following alternation.
You could also omit the word boundary in this part \b.png and escape the dot to match it literally.
code :
b0+(100|[1-9][0-9]?)?\.png
b0+([1-9][0-9]?|[12][0-9]{2}|3[0-6][0-9]|37[0-3])?\.png


Share : facebook icon twitter icon

Regex to allow a range of numbers from negative to positive within a range and allow 2 decimals


By : alphacrash
Date : March 29 2020, 07:55 AM
this one helps. There are a few difference between the two regexes. Firtly, the original one requires the digit to be everything in the string. The second one will find any separate number in the string. Example:
code :
1000.00 USD
^-?(?:\d{1,3}(?:[.]\d{1,2})?|1000(?:[.]0{1,2})?)$
\b-?(?:\d{1,3}(?:[.]\d{1,2})?|1000(?:[.]0{1,2})?)\b

Regex to accept numbers and/or number range separated by commas, but between range 1-64


By : Dave
Date : March 29 2020, 07:55 AM
I hope this helps . I need to validate a string entered by user. The string should allow numbers or ranges, separated by comma. The numbers must be between 1 and 64. , Here you go,
code :
^(?:6[0-4]|[1-5]\d|[1-9])(?: *- *(?:6[0-4]|[1-5]\d|[1-9]))?(?: *, *(?:6[0-4]|[1-5]\d|[1-9])(?: *- *(?:6[0-4]|[1-5]\d|[1-9]))?)*$

How to match both numbers and range of numbers in a CSV-like string with regex?


By : Sebastian
Date : March 29 2020, 07:55 AM
hope this fix your issue C# CSV String Parsing
Use the built-in CSV parser and check each field separately:
code :
using Microsoft.VisualBasic.FileIO;
....
var str = "123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;";
var csv_parser = new TextFieldParser(new StringReader(str));
csv_parser.HasFieldsEnclosedInQuotes = false;   // Fields are not enclosed with quotes
csv_parser.SetDelimiters(";");                  // Setting delimiter
string[] fields;
var range_fields = new List<string>();
var integer_fields = new List<string>();
while (!csv_parser.EndOfData)
{
    fields = csv_parser.ReadFields();
    foreach (var field in fields)
    {
        if (!string.IsNullOrWhiteSpace(field) && field.All(x => Char.IsDigit(x)))
        {
            integer_fields.Add(field);
            Console.WriteLine(string.Format("Intger field: {0}", field));
        }
        else if (!string.IsNullOrWhiteSpace(field) && Regex.IsMatch(field, @"\d+-\d+"))
        {
             range_fields.Add(field);
             Console.WriteLine(string.Format("Range field: {0}", field));
        }
    }
}
csv_parser.Close();
Range field: 123-234
Range field: 45-67
Intger field: 890
Range field: 11-22
Intger field: 123
Intger field: 123
Range field: 44-55
Range field: 098-567
Intger field: 890
(?<=^|;)((?<range>\d+-\d+)|(?<integer>\d+))(?=$|;)
var s = "123-234;FOO-456;45-67;FOO-FOO;890;FOO-123;11-22;123;123;44-55;098-567;890;123-FOO;";
var rx = new Regex(@"(?<=^|;)((?<range>\d+-\d+)|(?<integer>\d+))(?=$|;)", RegexOptions.ExplicitCapture);
var result = rx.Matches(s)
        .Cast<Match>()
        .Select(x => x.Groups["range"].Success ? 
            x.Groups["range"].Value : x.Groups["integer"].Value
        ).ToList();
foreach (var x in result)
    Console.WriteLine(x);

Regex to accept numbers and/or number range separated by commas, but between range 1-4093


By : user6521273
Date : March 29 2020, 07:55 AM
wish of those help I need a regex to validate VLAN string entered by user. The string should allow numbers or ranges, separated by comma. The numbers must be between 1 and 4093. , To match a number from 1 to 4093 one can use:
code :
(?:[1-9]\d{0,2}|[1-3]\d{3}|40(?:[0-8]\d|9[0-3]))
^(N)(?:[,-] *(N)?)*$
^(?:[1-9]\d{0,2}|[1-3]\d{3}|40(?:[0-8]\d|9[0-3]))(?:[,-] *(?:[1-9]\d{0,2}|[1-3]\d{3}|40(?:[0-8]\d|9[0-3]))?)*$

Can regex be used to validate numbers OUTSIDE a range of specific numbers?


By : Mark Winkel
Date : March 29 2020, 07:55 AM
Any of those help I have referred to several SO webpages for the answer to my question, but I keep reading that regex should not be used for validating numbers which are less than or greater than a certain range. I want to ensure that a user enters numbers within the following ranges: 11--20 and 65-100. Anything less than 11 will not be allowed, anything between 21 and 64 will not be allowed and anything from 101 above will not be allowed. I realize I can write something like , The regex would be less readable but like
shadow
Privacy Policy - Terms - Contact Us © voile276.org