Skip to content

Instantly share code, notes, and snippets.

@AlbericC
Created October 31, 2015 10:55
Show Gist options
  • Save AlbericC/8c44f3ea2ee2dbeea612 to your computer and use it in GitHub Desktop.
Save AlbericC/8c44f3ea2ee2dbeea612 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"here is a text i'd like to grab.\"]\n"
]
}
],
"source": [
"import re\n",
"\n",
"s = \"** here is a text i'd like to grab.\"\n",
"\n",
"print(re.findall('^[\\*\\ ]+(.*)',s))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['yepee']\n",
"['stars and spaces are ignored at beginning of a line ! ']\n",
"['even when there are no stars ! ']\n",
"['']\n",
"[]\n",
"['well, stars like (*) this one are kept. ']\n"
]
}
],
"source": [
"slist = \"\"\"\n",
"** yepee\n",
"* * stars and spaces are ignored at beginning of a line ! \n",
" even when there are no stars ! \n",
" \n",
"above line had blank space only. this one starts with no star nor space\n",
"** ** * ** ** * * * ** ** ** ***** ** * well, stars like (*) this one are kept. \n",
"\"\"\".split('\\n') # meh.\n",
"\n",
"for s in slist:\n",
" if s: # ignore empty lines\n",
" print(re.findall('^[\\*\\ ]+(.*)',s))"
]
}
],
"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.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment