Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

image name validate using regex python

# Python3 program to validate
# image file extension using regex
import re
 
# Function to validate
# image file extension . 
def imageFile(str):
 
    # Regex to check valid image file extension.
    regex = "([^s]+(.(?i)(jpe?g|png|gif|bmp))$)"
     
    # Compile the ReGex
    p = re.compile(regex)
 
    # If the string is empty
    # return false
    if (str == None):
        return False
 
    # Return if the string
    # matched the ReGex
    if(re.search(p, str)):
        return True
    else:
        return False
 
# Driver code
 
# Test Case 1:
str1 = "abc.png"
print(imageFile(str1))
 
# Test Case 2:
str2 = "im.jpg"
print(imageFile(str2))
 
# Test Case 3:
str3 = ".gif"
print(imageFile(str3))
 
# Test Case 4:
str4 = "abc.mp3"
print(imageFile(str4))
 
# Test Case 5:
str5 = " .jpg"
print(imageFile(str5))
 
# This code is contributed by avanitrachhadiya2155
Comment

image name validate using regex python

# Python3 program to validate
# image file extension using regex
import re
 
# Function to validate
# image file extension . 
def imageFile(str):
 
    # Regex to check valid image file extension.
    regex = "([^s]+(.(?i)(jpe?g|png|gif|bmp))$)"
     
    # Compile the ReGex
    p = re.compile(regex)
 
    # If the string is empty
    # return false
    if (str == None):
        return False
 
    # Return if the string
    # matched the ReGex
    if(re.search(p, str)):
        return True
    else:
        return False
 
# Driver code
 
# Test Case 1:
str1 = "abc.png"
print(imageFile(str1))
 
# Test Case 2:
str2 = "im.jpg"
print(imageFile(str2))
 
# Test Case 3:
str3 = ".gif"
print(imageFile(str3))
 
# Test Case 4:
str4 = "abc.mp3"
print(imageFile(str4))
 
# Test Case 5:
str5 = " .jpg"
print(imageFile(str5))
 
# This code is contributed by avanitrachhadiya2155
Comment

PREVIOUS NEXT
Code Example
Python :: python tkinter button multiple commands 
Python :: matrix of matrices python grepper 
Python :: custom_settings in scrpay 
Python :: python chatbot speech recognition 
Python :: how to drag a box on your screen python 
Python :: python dataframe update if not new row 
Python :: python cd to file 
Python :: python 5 minimal values from array 
Python :: how to add previous and next in tkinter in python 
Python :: monthly precipitation in python 
Python :: iptc text classification example 
Python :: adding attributes and metadata to a dataset using xarray 
Python :: in python, i am pustin two star before paramerter what is that men 
Python :: python: subset top 5 values in a column 
Python :: cumulative chart python plotly 
Python :: pop function second argument in python 
Python :: QAction pressed pyqt5 
Python :: what is mapping in os 
Python :: plot idl 
Python :: how to let the user input desmials in python 
Python :: Prints out the schema in the tree format 
Python :: how to upgrade python from 2.7 to 2.9 on ubuntu 14.04 
Python :: torch print floating precision 
Python :: get_absolute_url method on the model 
Python :: break py 
Python :: can the function inside a function be global if the function before it is global 
Python :: from flask_paginate import get_page_parameter 
Python :: Degrees conversion function in Python 
Python :: cairo.context transform vertical text python 
Python :: capturing-video-from-two-cameras-in-opencv-at-once 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =