Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to find, search and split the strings in the file using regular expressions in python?

Description

To write a piece of python code to find, search and split particular string in a file using regular expressions.

Process

  Import necessary libraries.

  Load the data file. (Text file).

  Initialize the constructor, findall().

  Pass the string to the constructor.

  Print the results.

Sample Code

#import libraries
import pandas as pd
import re
names = [‘text’]

data = pd.read_csv(‘……/read_it.txt’, names=names)
print(“Original strings in the text file\n\n”,data)
print(“\n”)

#find all
text = data.iloc[:,0]
find = re.findall(“Python”,str(text))
print(“Results for findall()\n”,find)
print(“\n”)

#Search
search = re.search(“easy”,str(text))
print(“Results for search()\n”,search)
print(“\n”)

#split
split = re.split(“\n”,str(text))
print(“Results for split()\n”,split)

Screenshots
find, search and split the strings in the file using regular expressions in python