Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to get each word in a string

# Python3 code to demonstrate
# to extract words from string
# using regex( findall() )
import re
 
# initializing string 
test_string = "Geeksforgeeks,    is best @# Computer Science Portal.!!!"
 
# printing original string
print ("The original string is : " +  test_string)
 
# using regex( findall() )
# to extract words from string
res = re.findall(r'w+', test_string)
 
# printing result
print ("The list of words is : " +  str(res))

#Output>>> [‘Geeksforgeeks’, ‘is’, ‘best’, ‘Computer’, ‘Science’, ‘Portal’]
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #word #string
ADD COMMENT
Topic
Name
8+9 =