codeparrot/xlcost-text-to-code huggingface dataset:
Check three or more consecutive identical characters or numbers | Python3 program to check three or more consecutiveidentical characters or numbers using regular expression ; Function to check three or more consecutiveidentical characters or numbers using regular expression ; Regex to check three or more consecutive identical characters or numbers ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidGUID ( str ) : NEW_LINE INDENT regex = " \\b ( [ a - zA - Z0-9 ] ) \\1\\1 + \\b " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " aaa " NEW_LINE print ( isValidGUID ( str1 ) ) NEW_LINE str2 = "11111" NEW_LINE print ( isValidGUID ( str2 ) ) NEW_LINE str3 = " aaab " NEW_LINE print ( isValidGUID ( str3 ) ) NEW_LINE str4 = " abc " NEW_LINE print ( isValidGUID ( str4 ) ) NEW_LINE str5 = " aa " NEW_LINE print ( isValidGUID ( str5 ) ) NEW_LINE
How to validate MAC address using Regular Expression | Python3 program to validate MAC address using using regular expression ; Function to validate MAC address . ; Regex to check valid MAC address ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidMACAddress ( str ) : NEW_LINE INDENT regex = ( " ^ ( [0-9A - Fa - f ] {2 } [ : - ] ) " + " { 5 } ( [0-9A - Fa - f ] {2 } ) | " + " ( [0-9a - fA - F ] {4 } \\ . " + " [ 0-9a - fA - F ] {4 } \\ . " + " [ 0-9a - fA - F ] {4 } ) $ " ) NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "01-23-45-67-89 - AB " NEW_LINE print ( isValidMACAddress ( str1 ) ) NEW_LINE str2 = "01:23:45:67:89 : AB " NEW_LINE print ( isValidMACAddress ( str2 ) ) NEW_LINE str3 = "0123.4567.89AB " NEW_LINE print ( isValidMACAddress ( str3 ) ) NEW_LINE str4 = "01-23-45-67-89 - AH " NEW_LINE print ( isValidMACAddress ( str4 ) ) NEW_LINE str5 = "01-23-45-67 - AH " NEW_LINE print ( isValidMACAddress ( str5 ) ) NEW_LINE
How to validate GUID ( Globally Unique Identifier ) using Regular Expression | Python3 program to validate GUID ( Globally Unique Identifier ) using regular expression ; Function to validate GUID ( Globally Unique Identifier ) ; Regex to check valid GUID ( Globally Unique Identifier ) ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import re NEW_LINE def isValidGUID ( str ) : NEW_LINE INDENT regex = " ^ [ { ] ? [ 0-9a - fA - F ] {8 } " + " - ( [ 0-9a - fA - F ] {4 } - ) " + " { 3 } [ 0-9a - fA - F ] {12 } [ } ] ? $ " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "123e4567 - e89b - 12d3" + " - a456-9AC7CBDCEE52" NEW_LINE print ( isValidGUID ( str1 ) ) NEW_LINE str2 = " { 123e4567 - e89b - 12d3 - " + " a456-9AC7CBDCEE52 } " NEW_LINE print ( isValidGUID ( str2 ) ) NEW_LINE str3 = "123e4567 - h89b - 12d3 - a456" + " - 9AC7CBDCEE52" NEW_LINE print ( isValidGUID ( str3 ) ) NEW_LINE str4 = "123e4567 - h89b - 12d3 - a456" NEW_LINE print ( isValidGUID ( str4 ) ) NEW_LINE
How to validate Indian driving license number using Regular Expression | Python program to validate Indian driving license number using regular expression ; Function to validate Indian driving license number . ; Regex to check valid Indian driving license number ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidLicenseNo ( str ) : NEW_LINE INDENT regex = ( " ^ ( ( [ A - Z ] {2 } [ 0-9 ] { 2 } ) " + " ( ▁ ) | ( [ A - Z ] {2 } - [0-9 ] " + " { 2 } ) ) ( (19 ▁ 20 ) [ 0-9 ] " + " [ 0-9 ] ) [0-9 ] { 7 } $ " ) NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " HR - 0619850034761" NEW_LINE print ( isValidLicenseNo ( str1 ) ) NEW_LINE str2 = " UP14 ▁ 20160034761" NEW_LINE print ( isValidLicenseNo ( str2 ) ) NEW_LINE str3 = "12HR - 37200602347" NEW_LINE print ( isValidLicenseNo ( str3 ) ) NEW_LINE str4 = " MH27 ▁ 30123476102" NEW_LINE print ( isValidLicenseNo ( str4 ) ) NEW_LINE str5 = " GJ - 2420180" NEW_LINE print ( isValidLicenseNo ( str5 ) ) NEW_LINE
Count subtrees that sum up to a given value x only using single recursive function | Structure of a node of binary tree ; Function to get a new node ; Allocate space ; Utility function to count subtress that sum up to a given value x ; Driver code ; binary tree creation 5 / \ - 10 3 / \ / \ 9 8 - 4 7
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def getNode ( data ) : NEW_LINE INDENT newNode = Node ( data ) NEW_LINE return newNode NEW_LINE DEDENT count = 0 NEW_LINE ptr = None NEW_LINE def countSubtreesWithSumXUtil ( root , x ) : NEW_LINE INDENT global count , ptr NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE if ( root == None ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT l += countSubtreesWithSumXUtil ( root . left , x ) NEW_LINE r += countSubtreesWithSumXUtil ( root . right , x ) NEW_LINE if ( l + r + root . data == x ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( ptr != root ) : NEW_LINE INDENT return l + root . data + r NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = getNode ( 5 ) NEW_LINE root . left = getNode ( - 10 ) NEW_LINE root . right = getNode ( 3 ) NEW_LINE root . left . left = getNode ( 9 ) NEW_LINE root . left . right = getNode ( 8 ) NEW_LINE root . right . left = getNode ( - 4 ) NEW_LINE root . right . right = getNode ( 7 ) NEW_LINE x = 7 NEW_LINE ptr = root NEW_LINE print ( " Count ▁ = ▁ " + str ( countSubtreesWithSumXUtil ( root , x ) ) ) NEW_LINE DEDENT
How to validate Indian Passport number using Regular Expression | Python3 program to validate passport number of India using regular expression ; Function to validate the pin code of India . ; Regex to check valid pin code of India . ; Compile the ReGex ; If the string is empty return false ; Pattern class contains matcher ( ) method to find matching between given string and regular expression . ; Return True if the string matched the ReGex else False ; Driver code . ; Test Case 1 ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidPassportNo ( string ) : NEW_LINE INDENT regex = " ^ [ A - PR - WYa - pr - wy ] [1-9 ] \\d " + p = re . compile ( regex ) NEW_LINE if ( string == ' ' ) : NEW_LINE INDENT return False NEW_LINE DEDENT m = re . match ( p , string ) NEW_LINE if m is None : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = " A21 ▁ 90457" NEW_LINE print ( isValidPassportNo ( str1 ) ) NEW_LINE str2 = " A0296457" NEW_LINE print ( isValidPassportNo ( str2 ) ) NEW_LINE str3 = " Q2096453" NEW_LINE print ( isValidPassportNo ( str3 ) ) NEW_LINE str4 = "12096457" NEW_LINE print ( isValidPassportNo ( str4 ) ) NEW_LINE str5 = " A209645704" NEW_LINE print ( isValidPassportNo ( str5 ) ) NEW_LINE DEDENT
How to validate Visa Card number using Regular Expression | Python3 program to validate Visa Card number using regular expression ; Function to validate Visa Card number using regular expression . ; Regex to check valid Visa Card number ; Compile the ReGex ; If the string is empty return false ; Pattern class contains matcher ( ) method to find matching between given string and regular expression . ; Return True if the string matched the ReGex else False ; Driver code ; Test Case 1 ; Test Case 2 ; Test Case 3 ; Test Case 4 ; Test Case 5 str5 = "415a2760457" ;
import re NEW_LINE def isValidVisaCardNo ( string ) : NEW_LINE INDENT regex = " ^ 4[0-9 ] { 12 } ( ? : [0-9 ] { 3 } ) ? $ " ; NEW_LINE p = re . compile ( regex ) ; NEW_LINE if ( string == ' ' ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT m = re . match ( p , string ) ; NEW_LINE if m is None : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = "4155279860457" ; NEW_LINE print ( isValidVisaCardNo ( str1 ) ) ; NEW_LINE str2 = "4155279860457201" ; NEW_LINE print ( isValidVisaCardNo ( str2 ) ) ; NEW_LINE str3 = "4155279" ; NEW_LINE print ( isValidVisaCardNo ( str3 ) ) ; NEW_LINE str4 = "6155279860457" ; NEW_LINE print ( isValidVisaCardNo ( str4 ) ) ; NEW_LINE print ( isValidVisaCardNo ( str5 ) ) ; NEW_LINE DEDENT
How to validate MasterCard number using Regular Expression | Python3 program to validate Master Card number using regular expression ; Function to validate Master Card number using regular expression . ; Regex to check valid Master Card number . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 : str5 = "2221149a635843"
import re NEW_LINE def isValidMasterCardNo ( str ) : NEW_LINE INDENT regex = " ^ 5[1-5 ] [ 0-9 ] { 14 } | " + NEW_LINE INDENT " ^ ( 222[1-9 ] ▁ 22[3-9 ] \\d ▁ " + "2[3-6 ] \\d { 2 } ▁ 27[0-1 ] \\d ▁ " + "2720 ) [ 0-9 ] { 12 } $ " NEW_LINE DEDENT p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "5114496353984312" NEW_LINE print ( isValidMasterCardNo ( str1 ) ) NEW_LINE str2 = "2720822463109651" NEW_LINE print ( isValidMasterCardNo ( str2 ) ) NEW_LINE str3 = "5582822410" NEW_LINE print ( isValidMasterCardNo ( str3 ) ) NEW_LINE str4 = "6082822463100051" NEW_LINE print ( isValidMasterCardNo ( str4 ) ) NEW_LINE print ( isValidMasterCardNo ( str5 ) ) NEW_LINE
How to validate CVV number using Regular Expression | Python3 program to validate CVV ( Card Verification Value ) number using regex . ; Function to validate CVV ( Card Verification Value ) number . using regular expression . ; Regex to check valid CVV number . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : str4 = "5a1"
import re NEW_LINE def isValidCVVNumber ( str ) : NEW_LINE INDENT regex = " ^ [ 0-9 ] { 3,4 } $ " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "561" NEW_LINE print ( isValidCVVNumber ( str1 ) ) NEW_LINE str2 = "5061" NEW_LINE print ( isValidCVVNumber ( str2 ) ) NEW_LINE str3 = "50614" NEW_LINE print ( isValidCVVNumber ( str3 ) ) NEW_LINE print ( isValidCVVNumber ( str4 ) ) NEW_LINE
How to validate IFSC Code using Regular Expression | Python3 program to validate IFSC ( Indian Financial System ) Code using regular expression ; Function to validate IFSC ( Indian Financial System ) Code using regular expression . ; Regex to check valid IFSC Code . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import re NEW_LINE def isValidIFSCode ( str ) : NEW_LINE INDENT regex = " ^ [ A - Z ] {4}0 [ A - Z0-9 ] { 6 } $ " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " SBIN0125620" NEW_LINE print ( isValidIFSCode ( str1 ) ) NEW_LINE str2 = " SBIN0125" NEW_LINE print ( isValidIFSCode ( str2 ) ) NEW_LINE str3 = "1234SBIN012" NEW_LINE print ( isValidIFSCode ( str3 ) ) NEW_LINE str4 = " SBIN7125620" NEW_LINE print ( isValidIFSCode ( str4 ) ) NEW_LINE
How to validate GST ( Goods and Services Tax ) number using Regular Expression | Python3 program to validate GST ( Goods and Services Tax ) number using regular expression ; Function to validate GST ( Goods and Services Tax ) number . ; Regex to check valid GST ( Goods and Services Tax ) number ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidMasterCardNo ( str ) : NEW_LINE INDENT regex = " ^ [ 0-9 ] { 2 } [ A - Z ] {5 } [ 0-9 ] { 4 } " + NEW_LINE INDENT " [ A - Z ] {1 } [ 1-9A - Z ] {1 } " + NEW_LINE DEDENT p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "06BZAHM6385P6Z2" NEW_LINE print ( isValidMasterCardNo ( str1 ) ) NEW_LINE str2 = "06BZAF67" NEW_LINE print ( isValidMasterCardNo ( str2 ) ) NEW_LINE str3 = " AZBZAHM6385P6Z2" NEW_LINE print ( isValidMasterCardNo ( str3 ) ) NEW_LINE str4 = "06BZ63AHM85P6Z2" NEW_LINE print ( isValidMasterCardNo ( str4 ) ) NEW_LINE str5 = "06BZAHM6385P6F2" NEW_LINE print ( isValidMasterCardNo ( str5 ) ) NEW_LINE
How to validate HTML tag using Regular Expression | Python3 program to validate HTML tag using regex . using regular expression ; Function to validate HTML tag using regex . ; Regex to check valid HTML tag using regex . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import re NEW_LINE def isValidHTMLTag ( str ) : NEW_LINE INDENT regex = " < ( \ " [ ^ \ " ] * \ " ▁ ' [ ^ ' ] * ' ▁ [ ^ ' \ " > ] ) * > " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " < input ▁ value ▁ = ▁ ' > ' > " NEW_LINE print ( isValidHTMLTag ( str1 ) ) NEW_LINE str2 = " < br / > " NEW_LINE print ( isValidHTMLTag ( str2 ) ) NEW_LINE str3 = " br / > " NEW_LINE print ( isValidHTMLTag ( str3 ) ) NEW_LINE str4 = " < ' br / > " NEW_LINE print ( isValidHTMLTag ( str4 ) ) NEW_LINE
How to validate a domain name using Regular Expression | Python3 program to validate domain name using regular expression ; Function to validate domain name . ; Regex to check valid domain name . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidDomain ( str ) : NEW_LINE INDENT regex = " ^ ( ( ? ! - ) [ A - Za - z0-9 - ] " + NEW_LINE INDENT " { 1,63 } ( ? < ! - ) \\ . ) " + NEW_LINE DEDENT p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " geeksforgeeks . org " NEW_LINE print ( isValidDomain ( str1 ) ) NEW_LINE str2 = " contribute . geeksforgeeks . org " NEW_LINE print ( isValidDomain ( str2 ) ) NEW_LINE str3 = " - geeksforgeeks . org " NEW_LINE print ( isValidDomain ( str3 ) ) NEW_LINE str4 = " geeksforgeeks . o " NEW_LINE print ( isValidDomain ( str4 ) ) NEW_LINE str5 = " . org " NEW_LINE print ( isValidDomain ( str5 ) ) NEW_LINE
How to validate SSN ( Social Security Number ) using Regular Expression | Python3 program to validate SSN ( Social Security Number ) using regular expression ; Function to validate SSN ( Social Security Number ) . ; Regex to check valid SSN ( Social Security Number ) . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import re NEW_LINE def isValidSSN ( str ) : NEW_LINE INDENT regex = " ^ ( ? ! 666 ▁ 000 ▁ 9\\d { 2 } ) \\d { 3 } - ( ? !00 ) \\d { 2 } - ( ? !0{4 } ) \\d { 4 } $ " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "856-45-6789" NEW_LINE print ( isValidSSN ( str1 ) ) NEW_LINE str2 = "000-45-6789" NEW_LINE print ( isValidSSN ( str2 ) ) NEW_LINE str3 = "856-452-6789" NEW_LINE print ( isValidSSN ( str3 ) ) NEW_LINE str4 = "856-45-0000" NEW_LINE print ( isValidSSN ( str4 ) ) NEW_LINE
How to validate image file extension using Regular Expression | Python3 program to validate image file extension using regex ; Function to validate image file extension . ; Regex to check valid image file extension . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def imageFile ( str ) : NEW_LINE INDENT regex = " ( [ ^ \\s ] + ( \\ . ( ? i ) ( jpe ? g ▁ png ▁ gif ▁ bmp ) ) $ ) " NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = " abc . png " NEW_LINE print ( imageFile ( str1 ) ) NEW_LINE str2 = " im . jpg " NEW_LINE print ( imageFile ( str2 ) ) NEW_LINE str3 = " . gif " NEW_LINE print ( imageFile ( str3 ) ) NEW_LINE str4 = " abc . mp3" NEW_LINE print ( imageFile ( str4 ) ) NEW_LINE str5 = " ▁ . jpg " NEW_LINE print ( imageFile ( str5 ) ) NEW_LINE
How to check Aadhar number is valid or not using Regular Expression | Python3 program to validate Aadhar number using regex . ; Function to validate Aadhar number . ; Regex to check valid Aadhar number . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : str4 = "3675 ▁ 98AF ▁ 602" ; Test Case 5 :
import re NEW_LINE def isValidAadharNumber ( str ) : NEW_LINE INDENT regex = ( " ^ [ 2-9 ] { 1 } [ 0-9 ] { 3 } \\ " + " s [ 0-9 ] { 4 } \\s [ 0-9 ] { 4 } $ " ) NEW_LINE p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT str1 = "3675 ▁ 9834 ▁ 6015" NEW_LINE print ( isValidAadharNumber ( str1 ) ) NEW_LINE str2 = "4675 ▁ 9834 ▁ 6012 ▁ 8" NEW_LINE print ( isValidAadharNumber ( str2 ) ) NEW_LINE str3 = "0175 ▁ 9834 ▁ 6012" NEW_LINE print ( isValidAadharNumber ( str3 ) ) NEW_LINE print ( isValidAadharNumber ( str4 ) ) NEW_LINE str5 = "417598346012" NEW_LINE print ( isValidAadharNumber ( str5 ) ) NEW_LINE
How to validate pin code of India using Regular Expression | Python3 program to validate the pin code of India using Regular Expression . ; Function to validate the pin code of India . ; Regex to check valid pin code of India . ; Compile the ReGex ; If the pin code is empty return false ; Pattern class contains matcher ( ) method to find matching between given pin code and regular expression . ; Return True if the pin code matched the ReGex else False ; Driver code ; Test case 1 ; Test case 2 : ; Test case 3 : ; Test case 4 :
import re NEW_LINE def isValidPinCode ( pinCode ) : NEW_LINE INDENT regex = " ^ [ 1-9 ] { 1 } [ 0-9 ] { 2 } \\s { 0,1 } [ 0-9 ] { 3 } $ " ; NEW_LINE p = re . compile ( regex ) ; NEW_LINE if ( pinCode == ' ' ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT m = re . match ( p , pinCode ) ; NEW_LINE if m is None : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT num1 = "132103" ; NEW_LINE print ( num1 , " : ▁ " , isValidPinCode ( num1 ) ) ; NEW_LINE num2 = "201 ▁ 305" ; NEW_LINE print ( num2 , " : ▁ " , isValidPinCode ( num2 ) ) ; NEW_LINE num3 = "014205" ; NEW_LINE print ( num3 , " : ▁ " , isValidPinCode ( num3 ) ) ; NEW_LINE num4 = "1473598" ; NEW_LINE print ( num4 , " : ▁ " , isValidPinCode ( num4 ) ) ; NEW_LINE DEDENT
How to validate time in 24 | Python3 program to validate the time in 24 - hour format using Regular Expression . ; Function to validate the time in 24 - hour format ; Regex to check valid time in 24 - hour format . ; Compile the ReGex ; If the time is empty return false ; Pattern class contains matcher ( ) method to find matching between given time and regular expression . ; Return True if the time matched the ReGex otherwise False ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import re NEW_LINE def isValidTime ( time ) : NEW_LINE INDENT regex = " ^ ( [01 ] ? [0-9 ] ▁ 2[0-3 ] ) : [ 0-5 ] [ 0-9 ] $ " ; NEW_LINE p = re . compile ( regex ) ; NEW_LINE if ( time == " " ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT m = re . search ( p , time ) ; NEW_LINE if m is None : NEW_LINE INDENT return False ; NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = "13:05" ; NEW_LINE print ( str1 , " : ▁ " , isValidTime ( str1 ) ) ; NEW_LINE str2 = "02:15" ; NEW_LINE print ( str2 , " : ▁ " , isValidTime ( str2 ) ) ; NEW_LINE str3 = "24:00" ; NEW_LINE print ( str3 , " : ▁ " , isValidTime ( str3 ) ) ; NEW_LINE str4 = "10:60" ; NEW_LINE print ( str4 , " : ▁ " , isValidTime ( str4 ) ) ; NEW_LINE str5 = "10:15 ▁ PM " ; NEW_LINE print ( str5 , " : ▁ " , isValidTime ( str5 ) ) ; NEW_LINE DEDENT
How to validate Hexadecimal Color Code using Regular Expression | Python3 program to validate hexadecimal colour code using Regular Expression ; Function to validate hexadecimal color code . ; Compile the ReGex ; If the string is empty return false ; Return if the string matched the ReGex ; Test Case 1 : str1 = "1AFFa1" ; Test Case 2 : str2 = " F00" ; Test Case 3 : ; Test Case 4 : str4 = "123abce " ; Test Case 5 : str5 = " afafah "
import re NEW_LINE def isValidHexaCode ( str ) : NEW_LINE INDENT p = re . compile ( regex ) NEW_LINE if ( str == None ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( re . search ( p , str ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT print ( str1 , " : " , isValidHexaCode ( str1 ) ) NEW_LINE print ( str2 , " : " , isValidHexaCode ( str2 ) ) NEW_LINE str3 = "123456" NEW_LINE print ( str3 , " : " , isValidHexaCode ( str3 ) ) NEW_LINE print ( str4 , " : " , isValidHexaCode ( str4 ) ) NEW_LINE print ( str5 , " : " , isValidHexaCode ( str5 ) ) NEW_LINE