split() regex in python by R4R Team

- split() is a python regex function that returns a list where the string has been split at each match:

Syntax-

re.split(pattern,string,flag=0)

Example-

string is s="This-is-string"
re.split("-",s) will return ["This","is","string"]


program-

import re

print("Enter the string")
s=input()

#split according to the white space
x=re.split("s",s)
print(x)

#split with flag 1
x=re.split("s",s,1)
print(x)

#split with flag 2
x=re.split("s",s,2)
print(x)


output-

Enter the string
This is a programming language in this universe
['This', 'is', 'a', 'programming', 'language', 'in', 'this', 'universe']
['This', 'is a programming language in this universe']
['This', 'is', 'a programming language in this universe']


-In this program, we take a input of the string and then split the string on the basis of white space and flag value.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!