rodrigosantosbr

Regex check integer >= 250

Jan 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

Site:

https://regex101.com/
https://www.jdoodle.com/python3-programming-online
https://playcode.io/online-javascript-editor
https://www.cs.bham.ac.uk/~hxt/research/rxxr2/regexlib-input.txt


Javascript

var re = /^\d{4,}$|^[3-9]\d{2}$|^2[5-9]\d$/;
var term1 = 248;
var term2 = 249;
var term3 = 250;
var term4 = 251;

if (re.exec(term1)) {
    console.log(term1+": Valid");
}
else {
    console.log(term1+": Invalid");
}

if (re.exec(term2)) {
    console.log(term2+": Valid");
}
else {
    console.log(term2+": Invalid");
}

if (re.exec(term3)) {
    console.log(term3+": Valid");
}
else {
    console.log(term3+": Invalid");
}

if (re.exec(term4)) {
    console.log(term4+": Valid");
}
else {
    console.log(term4+": Invalid");
}

Python

import re
patt = r'^\d{4,}$|^[3-9]\d{2}$|^2[5-9]\d$'
term1 = str(248)
match1 = re.search(patt,term1)
term2 = str(250)
match2 = re.search(patt,term2)

if match1:
    print("Valid: {}".format(match1.group()))
else:
    print("Invalid: {}".format(term1))

if match2:
    print("Valid: {}".format(match2.group()))
else:
    print("Invalid: {}".format(term2))
Add Comment
Please, Sign In to add comment