├── README.md
└── Regular_Expression.ipynb
/README.md:
--------------------------------------------------------------------------------
1 | # Natural-Language-Processing
--------------------------------------------------------------------------------
/Regular_Expression.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "provenance": [],
7 | "authorship_tag": "ABX9TyPQ/yYEX6PFm+XSdRE/WxEV",
8 | "include_colab_link": true
9 | },
10 | "kernelspec": {
11 | "name": "python3",
12 | "display_name": "Python 3"
13 | },
14 | "language_info": {
15 | "name": "python"
16 | }
17 | },
18 | "cells": [
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {
22 | "id": "view-in-github",
23 | "colab_type": "text"
24 | },
25 | "source": [
26 | "
"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": 1,
32 | "metadata": {
33 | "id": "oBv2leIKFLpu"
34 | },
35 | "outputs": [],
36 | "source": [
37 | "import re"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "source": [
43 | "re.match('abc','abcdef')"
44 | ],
45 | "metadata": {
46 | "colab": {
47 | "base_uri": "https://localhost:8080/"
48 | },
49 | "id": "_LSP23UyUGy4",
50 | "outputId": "d9c27f7e-857c-4ed2-f0a5-600f65906839"
51 | },
52 | "execution_count": 22,
53 | "outputs": [
54 | {
55 | "output_type": "execute_result",
56 | "data": {
57 | "text/plain": [
58 | ""
59 | ]
60 | },
61 | "metadata": {},
62 | "execution_count": 22
63 | }
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "source": [
69 | "word_regex = '\\w+'\n",
70 | "re.match(word_regex,'hi there!')"
71 | ],
72 | "metadata": {
73 | "colab": {
74 | "base_uri": "https://localhost:8080/"
75 | },
76 | "id": "Ewoy3f3LUOyt",
77 | "outputId": "3705a18b-3e82-463f-c498-acde4e60a98d"
78 | },
79 | "execution_count": 23,
80 | "outputs": [
81 | {
82 | "output_type": "execute_result",
83 | "data": {
84 | "text/plain": [
85 | ""
86 | ]
87 | },
88 | "metadata": {},
89 | "execution_count": 23
90 | }
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "source": [
96 | "my_string = \"Let's write RegEx!\"\n",
97 | "PATTERN = r\"\\w+\"\n",
98 | "re.findall(PATTERN, my_string)"
99 | ],
100 | "metadata": {
101 | "colab": {
102 | "base_uri": "https://localhost:8080/"
103 | },
104 | "id": "SZcSZ5luFhEe",
105 | "outputId": "c83cc7f7-cfff-4597-faab-70bc2cda5074"
106 | },
107 | "execution_count": 12,
108 | "outputs": [
109 | {
110 | "output_type": "execute_result",
111 | "data": {
112 | "text/plain": [
113 | "['Let', 's', 'write', 'RegEx']"
114 | ]
115 | },
116 | "metadata": {},
117 | "execution_count": 12
118 | }
119 | ]
120 | },
121 | {
122 | "cell_type": "markdown",
123 | "source": [
124 | ""
125 | ],
126 | "metadata": {
127 | "id": "QsbCfMgxGHVM"
128 | }
129 | },
130 | {
131 | "cell_type": "code",
132 | "source": [
133 | "# Write a pattern to match sentence endings: sentence_endings\n",
134 | "sentence_endings = r\"[.?!]\"\n",
135 | "\n",
136 | "# Split my_string on sentence endings and print the result\n",
137 | "print(re.split(sentence_endings, my_string))\n",
138 | "\n",
139 | "# Find all capitalized words in my_string and print the result\n",
140 | "capitalized_words = r\"[A-Z]\\w+\"\n",
141 | "print(re.findall(capitalized_words, my_string))\n",
142 | "\n",
143 | "# Split my_string on spaces and print the result\n",
144 | "spaces = r\"\\s+\"\n",
145 | "print(re.split(spaces, my_string))\n",
146 | "\n",
147 | "# Find all digits in my_string and print the result\n",
148 | "digits = r\"\\d+\"\n",
149 | "print(re.findall(digits, my_string))\n"
150 | ],
151 | "metadata": {
152 | "colab": {
153 | "base_uri": "https://localhost:8080/"
154 | },
155 | "id": "4djMD825Gvf7",
156 | "outputId": "c0a8732a-ed62-4d11-d16e-f3179834108c"
157 | },
158 | "execution_count": 13,
159 | "outputs": [
160 | {
161 | "output_type": "stream",
162 | "name": "stdout",
163 | "text": [
164 | "[\"Let's write RegEx\", '']\n",
165 | "['Let', 'RegEx']\n",
166 | "[\"Let's\", 'write', 'RegEx!']\n",
167 | "[]\n"
168 | ]
169 | }
170 | ]
171 | }
172 | ]
173 | }
--------------------------------------------------------------------------------