Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Script to Remove Special Characters From Text File Using Regular Expression Full Project

Posted on February 11, 2023

 

 

Welcome folks today in this blog post we will be removing special characters from the text file using regular expression in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
import re
string = open('input.txt').read()
new_str = re.sub('[^a-zA-Z0-9\n\.]','', string)
open('b.txt', 'w').write(new_str)

 

 

And now we need to create the input.txt file before you execute the python script and copy paste the below text which contains the special characters as shown below

 

 

input.txt

 

 

1
2
3
4
@###@@@dfsdfsd
sdfsdf
@##fdsfsdfsdf
sdfsdf$$sfsd

 

 

And after that you need to execute the above python script using the below command as shown below

 

 

python app.py

 

 

 

Recent Posts

  • Android Java Project to Store,Read & Delete Data Using SharedPreferences Example
  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme