{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 5 - Regex" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the regex task section, syntax used for the example text was retrieved from here: https://loremipsum.io/." ] }, { "cell_type": "code", "execution_count": 294, "metadata": {}, "outputs": [], "source": [ "example_text = \"Lorem ipsum dolorolo at sit amet, consectetur ipsumm adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco (laboris) nisi ut (aliquip) ex ea commodo consequat. [192.168.1.1:8080] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [192.168.1.254:80]\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1 Add the necessary libraries." ] }, { "cell_type": "code", "execution_count": 303, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2 Find how many times the word `ipsum` appears in the text." ] }, { "cell_type": "code", "execution_count": 304, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3 Find in the text how many times the string `ipsum` (not the word!) appears." ] }, { "cell_type": "code", "execution_count": 305, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "4 Search the text for everything after the word `Excepteur` (Note: the word Excepteur should not be included in the output!)" ] }, { "cell_type": "code", "execution_count": 306, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "5 Find all the words inside the brackets `()`." ] }, { "cell_type": "code", "execution_count": 307, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "6 Choose all the words that end with `at` (include the word 'at' also!)." ] }, { "cell_type": "code", "execution_count": 308, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "7 Find words that contain the string `olo` but do not start or end with that string." ] }, { "cell_type": "code", "execution_count": 309, "metadata": {}, "outputs": [], "source": [ "#" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "8 Next find all IP addresses with the following form: `ip-address:port-number` (eg 192.168.1.1:8080) without static search or `r'\\[.*?\\]'`/similar syntax which returns all the content inside the square brackets." ] }, { "cell_type": "code", "execution_count": 310, "metadata": {}, "outputs": [], "source": [ "#" ] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }