Write a function to check and print if a string starts with a substring using regex in Python


Topic: Write a function to check and print if a string starts with a substring using regex in Python

Solution

import re 
  
  
def find(string, sample) :    
  if (sample in string): 
  
      y = "^" + sample 
  
      x = re.search(y, string) 
  
      if x : 
          print("string starts with the given substring") 
  
      else : 
          print("string doesn't start with the given substring") 
  
  else : 
      print("entered string isn't a substring") 
	  
	  



List all Python Programs