codeparrot/xlcost-text-to-code huggingface dataset:
Minimum replacements required to make given Matrix palindromic | Java program for the above approach ; Function to count minimum changes to make the matrix palindromic ; Rows in the matrix ; Columns in the matrix ; Traverse the given matrix ; Store the frequency of the four cells ; Iterate over the map ; Min changes to do to make all ; Four elements equal ; Make the middle row palindromic ; Make the middle column palindromic ; Print minimum changes ; Driver Code ; Given matrix ; Function Call
import java . util . * ; class GFG { static void minchanges ( int [ ] [ ] mat ) { int N = mat . length ; int M = mat [ 0 ] . length ; int i , j , ans = 0 , x ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( i = 0 ; i < N / 2 ; i ++ ) { for ( j = 0 ; j < M / 2 ; j ++ ) { if ( mp . containsKey ( mat [ i ] [ M - 1 - j ] ) ) { mp . put ( mat [ i ] [ M - 1 - j ] , mp . get ( mat [ i ] [ M - 1 - j ] ) + 1 ) ; } else { mp . put ( mat [ i ] [ M - 1 - j ] , 1 ) ; } if ( mp . containsKey ( mat [ i ] [ j ] ) ) { mp . put ( mat [ i ] [ j ] , mp . get ( mat [ i ] [ j ] ) + 1 ) ; } else { mp . put ( mat [ i ] [ j ] , 1 ) ; } if ( mp . containsKey ( mat [ N - 1 - i ] [ M - 1 - j ] ) ) { mp . put ( mat [ N - 1 - i ] [ M - 1 - j ] , mp . get ( mat [ N - 1 - i ] [ M - 1 - j ] ) + 1 ) ; } else { mp . put ( mat [ N - 1 - i ] [ M - 1 - j ] , 1 ) ; } if ( mp . containsKey ( mat [ N - 1 - i ] [ j ] ) ) { mp . put ( mat [ N - 1 - i ] [ j ] , mp . get ( mat [ N - 1 - i ] [ j ] ) + 1 ) ; } else { mp . put ( mat [ N - 1 - i ] [ j ] , 1 ) ; } x = 0 ; for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { x = Math . max ( x , it . getValue ( ) ) ; } ans = ans + 4 - x ; mp . clear ( ) ; } } if ( N % 2 == 1 ) { for ( i = 0 ; i < M / 2 ; i ++ ) { if ( mat [ N / 2 ] [ i ] != mat [ N / 2 ] [ M - 1 - i ] ) ans ++ ; } } if ( M % 2 == 1 ) { for ( i = 0 ; i < N / 2 ; i ++ ) { if ( mat [ i ] [ M / 2 ] != mat [ N - 1 - i ] [ M / 2 ] ) ans ++ ; } } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 3 } , { 1 , 2 , 1 } } ; minchanges ( mat ) ; } }
Check if a number starts with another number or not | Java program for the above approach ; Function to check if B is a prefix of A or not ; Convert numbers into Strings ; Check if s2 is a prefix of s1 or not using starts_with ( ) function ; If result is true , print " Yes " ; Driver Code ; Given numbers ; Function call
class GFG { static void checkprefix ( int A , int B ) { String s1 = String . valueOf ( A ) ; String s2 = String . valueOf ( B ) ; boolean result ; result = s1 . startsWith ( s2 ) ; if ( result ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } public static void main ( String [ ] args ) { int A = 12345 , B = 12 ; checkprefix ( A , B ) ; } }
Check three or more consecutive identical characters or numbers | Java program to check three or more consecutive identical characters or numbers using regular expression ; Function to check three or more consecutive identical 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 ; Find match between given string and regular expression using Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isIdentical ( String str ) { String regex = " \\ b ( [ a - zA - Z0-9 ] ) \\ 1 \\ 1 + \\ b " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " aaa " ; System . out . println ( isIdentical ( str1 ) ) ; String str2 = "11111" ; System . out . println ( isIdentical ( str2 ) ) ; String str3 = " aaab " ; System . out . println ( isIdentical ( str3 ) ) ; String str4 = " abc " ; System . out . println ( isIdentical ( str4 ) ) ; String str5 = " aa " ; System . out . println ( isIdentical ( str5 ) ) ; } }
How to validate MAC address using Regular Expression | Java program to validate MAC address using regular expression ; Function to validate MAC address using regular expression ; Regex to check valid MAC address ; Compile the ReGex ; If the string is empty return false ; Find match between given string and regular expression uSing Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidMACAddress ( String str ) { String 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 } ) $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "01-23-45-67-89 - AB " ; System . out . println ( isValidMACAddress ( str1 ) ) ; String str2 = "01:23:45:67:89 : AB " ; System . out . println ( isValidMACAddress ( str2 ) ) ; String str3 = "0123.4567.89AB " ; System . out . println ( isValidMACAddress ( str3 ) ) ; String str4 = "01-23-45-67-89 - AH " ; System . out . println ( isValidMACAddress ( str4 ) ) ; String str5 = "01-23-45-67 - AH " ; System . out . println ( isValidMACAddress ( str5 ) ) ; } }
How to validate GUID ( Globally Unique Identifier ) using Regular Expression | Java program to validate GUID ( Globally Unique Identifier ) using regular expression ; Function to validate GUID ( Globally Unique Identifier ) using regular expression ; Regex to check valid GUID ( Globally Unique Identifier ) ; Compile the ReGex ; If the string is empty return false ; Find match between given string and regular expression uSing Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import java . util . regex . * ; class GFG { public static boolean isValidGUID ( String str ) { String regex = " ^ [ { ] ? [ 0-9a - fA - F ] { 8 } " + " - ( [ 0-9a - fA - F ] { 4 } - ) " + " { 3 } [ 0-9a - fA - F ] { 12 } [ } ] ? $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str2 = "123e4567 - e89b - 12d3" + " - a456-9AC7CBDCEE52" ; System . out . println ( isValidGUID ( str2 ) ) ; String str3 = " { 123e4567 - e89b - 12d3 - " + " a456-9AC7CBDCEE52 } " ; System . out . println ( isValidGUID ( str3 ) ) ; String str1 = "123e4567 - h89b - 12d3 - a456" + " - 9AC7CBDCEE52" ; System . out . println ( isValidGUID ( str1 ) ) ; String str4 = "123e4567 - h89b - 12d3 - a456" ; System . out . println ( isValidGUID ( str4 ) ) ; } }
How to validate Indian driving license number using Regular Expression | Java program to validate Indian driving license number using regular expression ; Function to validate Indian driving license number using regular expression ; Regex to check valid Indian driving license number ; Compile the ReGex ; If the string is empty return false ; Find match between given string and regular expression uSing Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidLicenseNo ( String str ) { String regex = " ^ ( ( [ A - Z ] { 2 } [ 0-9 ] { 2 } ) " + " ( ▁ ) | ( [ A - Z ] { 2 } - [0-9 ] " + " { 2 } ) ) ( (19 ▁ 20 ) [ 0-9 ] " + " [ 0-9 ] ) [0-9 ] { 7 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " HR - 0619850034761" ; System . out . println ( isValidLicenseNo ( str1 ) ) ; String str2 = " UP14 ▁ 20160034761" ; System . out . println ( isValidLicenseNo ( str2 ) ) ; String str3 = "12HR - 37200602347" ; System . out . println ( isValidLicenseNo ( str3 ) ) ; String str4 = " MH27 ▁ 30123476102" ; System . out . println ( isValidLicenseNo ( str4 ) ) ; String str5 = " GJ - 2420180" ; System . out . println ( isValidLicenseNo ( str5 ) ) ; } }
Count subtrees that sum up to a given value x only using single recursive function | Java program to find if there is a subtree with given sum ; Node class to create new node ; 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
import java . io . * ; class Node { int data ; Node left ; Node right ; Node ( int data ) { this . data = data ; } } class GFG { static int count = 0 ; static Node ptr ; int countSubtreesWithSumXUtil ( Node root , int x ) { int l = 0 , r = 0 ; if ( root == null ) return 0 ; l += countSubtreesWithSumXUtil ( root . left , x ) ; r += countSubtreesWithSumXUtil ( root . right , x ) ; if ( l + r + root . data == x ) count ++ ; if ( ptr != root ) return l + root . data + r ; return count ; } public static void main ( String [ ] args ) { Node root = new Node ( 5 ) ; root . left = new Node ( - 10 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 9 ) ; root . left . right = new Node ( 8 ) ; root . right . left = new Node ( - 4 ) ; root . right . right = new Node ( 7 ) ; int x = 7 ; ptr = root ; System . out . println ( " Count ▁ = ▁ " + new GFG ( ) . countSubtreesWithSumXUtil ( root , x ) ) ; } }
How to validate Indian Passport number using Regular Expression | Java program to validate passport number of India using regular expression ; Function to validate passport number of India using regular expression ; Regex to check valid . passport number of India ; Compile the ReGex ; If the string is empty return false ; Find match between given string and regular expression using Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidPassportNo ( String str ) { String regex = " ^ [ A - PR - WYa - pr - wy ] [1-9 ] \\ d " + " \\ s ? \\ d { 4 } [ 1-9 ] $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " A21 ▁ 90457" ; System . out . println ( isValidPassportNo ( str1 ) ) ; String str2 = " A0296457" ; System . out . println ( isValidPassportNo ( str2 ) ) ; String str3 = " Q2096453" ; System . out . println ( isValidPassportNo ( str3 ) ) ; String str4 = "12096457" ; System . out . println ( isValidPassportNo ( str4 ) ) ; String str5 = " A209645704" ; System . out . println ( isValidPassportNo ( str5 ) ) ; } }
How to validate Visa Card number using Regular Expression | Java 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 ; Find match between given string and regular expression using Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidVisaCardNo ( String str ) { String regex = " ^ 4[0-9 ] { 12 } ( ? : [0-9 ] { 3 } ) ? $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "4155279860457" ; System . out . println ( isValidVisaCardNo ( str1 ) ) ; String str2 = "4155279860457201" ; System . out . println ( isValidVisaCardNo ( str2 ) ) ; String str3 = "4155279" ; System . out . println ( isValidVisaCardNo ( str3 ) ) ; String str4 = "6155279860457" ; System . out . println ( isValidVisaCardNo ( str4 ) ) ; String str5 = "415a27 # # 60457" ; System . out . println ( isValidVisaCardNo ( str5 ) ) ; } }
How to validate MasterCard number using Regular Expression | Java 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 ; Find match between given string and regular expression using Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidMasterCardNo ( String str ) { String regex = " ^ 5[1-5 ] [ 0-9 ] { 14 } | " + " ^ ( 222[1-9 ] ▁ 22[3-9 ] \\ d ▁ " + "2[3-6 ] \\ d { 2 } ▁ 27[0-1 ] \\ d ▁ " + "2720 ) [ 0-9 ] { 12 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "5114496353984312" ; System . out . println ( isValidMasterCardNo ( str1 ) ) ; String str2 = "2720822463109651" ; System . out . println ( isValidMasterCardNo ( str2 ) ) ; String str3 = "5582822410" ; System . out . println ( isValidMasterCardNo ( str3 ) ) ; String str4 = "6082822463100051" ; System . out . println ( isValidMasterCardNo ( str4 ) ) ; String str5 = "2221149a635 # # 843" ; System . out . println ( isValidMasterCardNo ( str5 ) ) ; } }
How to validate CVV number using Regular Expression | Java 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 ; Find match between given string and regular expression uaing Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import java . util . regex . * ; class GFG { public static boolean isValidCVVNumber ( String str ) { String regex = " ^ [ 0-9 ] { 3,4 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "561" ; System . out . println ( isValidCVVNumber ( str1 ) ) ; String str2 = "5061" ; System . out . println ( isValidCVVNumber ( str2 ) ) ; String str3 = "50614" ; System . out . println ( isValidCVVNumber ( str3 ) ) ; String str4 = "5a # 1" ; System . out . println ( isValidCVVNumber ( str4 ) ) ; } }
How to validate IFSC Code using Regular Expression | Java 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 ; Pattern class contains matcher ( ) method to find matching between the given string and the regular expression . ; Return if the string matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import java . util . regex . * ; class GFG { public static boolean isValidIFSCode ( String str ) { String regex = " ^ [ A - Z ] { 4 } 0 [ A - Z0-9 ] { 6 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " SBIN0125620" ; System . out . println ( isValidIFSCode ( str1 ) ) ; String str2 = " SBIN0125" ; System . out . println ( isValidIFSCode ( str2 ) ) ; String str3 = "1234SBIN012" ; System . out . println ( isValidIFSCode ( str3 ) ) ; String str4 = " SBIN7125620" ; System . out . println ( isValidIFSCode ( str4 ) ) ; } }
How to validate GST ( Goods and Services Tax ) number using Regular Expression | Java program to validate the 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 ; Pattern class contains matcher ( ) method to find the matching between the given string and the regular expression . ; Return if the string matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidGSTNo ( String str ) { String regex = " ^ [ 0-9 ] { 2 } [ A - Z ] { 5 } [ 0-9 ] { 4 } " + " [ A - Z ] { 1 } [ 1-9A - Z ] { 1 } " + " Z [ 0-9A - Z ] { 1 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "06BZAHM6385P6Z2" ; System . out . println ( isValidGSTNo ( str1 ) ) ; String str2 = "06BZAF67" ; System . out . println ( isValidGSTNo ( str2 ) ) ; String str3 = " AZBZAHM6385P6Z2" ; System . out . println ( isValidGSTNo ( str3 ) ) ; String str4 = "06BZ63AHM85P6Z2" ; System . out . println ( isValidGSTNo ( str4 ) ) ; String str5 = "06BZAHM6385P6F2" ; System . out . println ( isValidGSTNo ( str5 ) ) ; } }
How to validate HTML tag using Regular Expression | Java program to validate HTML tag using regex . ; Function to validate HTML tag using regex . ; Regex to check valid HTML tag . ; Compile the ReGex ; If the string is empty return false ; Find match between given string and regular expression using Pattern . matcher ( ) ; Return if the string matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidHTMLTag ( String str ) { String regex = " < ( \" [ ^ \" ] * \" ▁ ' [ ^ ' ] * ' ▁ [ ^ ' \" > ] ) * > " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " < input ▁ value ▁ = ▁ ' > ' > " ; System . out . println ( isValidHTMLTag ( str1 ) ) ; String str2 = " < br / > " ; System . out . println ( isValidHTMLTag ( str2 ) ) ; String str3 = " br / > " ; System . out . println ( isValidHTMLTag ( str3 ) ) ; String str4 = " < ' br / > " ; System . out . println ( isValidHTMLTag ( str4 ) ) ; String str5 = " < input ▁ value ▁ = > ▁ > " ; System . out . println ( isValidHTMLTag ( str5 ) ) ; } }
How to validate a domain name using Regular Expression | Java 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 ; Pattern class contains matcher ( ) method to find the matching between the given string and regular expression . ; Return if the string matched the ReGex ; Driver Code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidDomain ( String str ) { String regex = " ^ ( ( ? ! - ) [ A - Za - z0-9 - ] " + " { 1,63 } ( ? < ! - ) \\ . ) " + " + [ A - Za - z ] { 2,6 } " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " geeksforgeeks . org " ; System . out . println ( isValidDomain ( str1 ) ) ; String str2 = " contribute . geeksforgeeks . org " ; System . out . println ( isValidDomain ( str2 ) ) ; String str3 = " - geeksforgeeks . org " ; System . out . println ( isValidDomain ( str3 ) ) ; String str4 = " geeksforgeeks . o " ; System . out . println ( isValidDomain ( str4 ) ) ; String str5 = " . org " ; System . out . println ( isValidDomain ( str5 ) ) ; } }
How to validate SSN ( Social Security Number ) using Regular Expression | Java program to check valid SSN ( Social Security Number ) using regex . ; Function to validate SSN ( Social Security Number ) . ; Regex to check SSN ( Social Security 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 if the string matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 :
import java . util . regex . * ; class GFG { public static boolean isValidSSN ( String str ) { String regex = " ^ ( ? ! 666 ▁ 000 ▁ 9 \\ d { 2 } ) \\ d { 3 } " + " - ( ? !00 ) \\ d { 2 } - " + " ( ? ! 0 { 4 } ) \\ d { 4 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "856-45-6789" ; ; System . out . println ( isValidSSN ( str1 ) ) ; String str2 = "000-45-6789" ; ; System . out . println ( isValidSSN ( str2 ) ) ; String str3 = "856-452-6789" ; System . out . println ( isValidSSN ( str3 ) ) ; String str4 = "856-45-0000" ; System . out . println ( isValidSSN ( str4 ) ) ; } }
How to validate image file extension using Regular Expression | Java program to check valid 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 ; Pattern class contains matcher ( ) method to find matching between given string and regular expression . ; Return if the string matched the ReGex ; Driver code ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean imageFile ( String str ) { String regex = " ( [ ^ \\ s ] + ( \\ . ( ? i ) ( jpe ? g ▁ png ▁ gif ▁ bmp ) ) $ ) " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " abc . png " ; System . out . println ( imageFile ( str1 ) ) ; String str2 = " im . jpg " ; System . out . println ( imageFile ( str2 ) ) ; String str3 = " . gif " ; System . out . println ( imageFile ( str3 ) ) ; String str4 = " abc . mp3" ; System . out . println ( imageFile ( str4 ) ) ; String str5 = " ▁ . jpg " ; System . out . println ( imageFile ( str5 ) ) ; } }
How to check Aadhar number is valid or not using Regular Expression | Java program to check valid 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 ; Pattern class contains matcher ( ) method to find matching between given string and regular expression . ; Return if the string matched the ReGex ; Driver Code . ; Test Case 1 : ; Test Case 2 : ; Test Case 3 : ; Test Case 4 : ; Test Case 5 :
import java . util . regex . * ; class GFG { public static boolean isValidAadharNumber ( String str ) { String regex = " ^ [ 2-9 ] { 1 } [ 0-9 ] { 3 } \\ s [ 0-9 ] { 4 } \\ s [ 0-9 ] { 4 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "3675 ▁ 9834 ▁ 6015" ; System . out . println ( isValidAadharNumber ( str1 ) ) ; String str2 = "4675 ▁ 9834 ▁ 6012 ▁ 8" ; System . out . println ( isValidAadharNumber ( str2 ) ) ; String str3 = "0175 ▁ 9834 ▁ 6012" ; System . out . println ( isValidAadharNumber ( str3 ) ) ; String str4 = "3675 ▁ 98AF ▁ 60#2" ; System . out . println ( isValidAadharNumber ( str4 ) ) ; String str5 = "417598346012" ; System . out . println ( isValidAadharNumber ( str5 ) ) ; } }