Skip to content

Instantly share code, notes, and snippets.

@EgZvor
Created August 9, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EgZvor/54c002aca823cddfa6cd to your computer and use it in GitHub Desktop.
Save EgZvor/54c002aca823cddfa6cd to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import re\n",
"\n",
"\n",
"f = open('D:\\english.srt')\n",
"f_new = open('D:\\english_without_shit.srt', 'w+')\n",
"pattern1 = re.compile(\"\\[.*\\]\")\n",
"pattern2 = re.compile(\".*\\]\")\n",
"pattern3 = re.compile(\"\\[.*\")\n",
"patts = [pattern1, pattern2, pattern3]\n",
"for row in f:\n",
" temp = row\n",
" if '[' in temp or ']' in temp:\n",
" for pat in patts:\n",
" substed = re.sub(pat, '', temp)\n",
" if len(substed) < len(temp):\n",
" temp = substed\n",
" break\n",
" f_new.writelines(temp)\n",
"f.close()\n",
"f_new.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment