Skip to content

Commit 137c491

Browse files
committed
Created using Colaboratory
1 parent d73f6c9 commit 137c491

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed

re.ipynb

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "re.ipynb",
7+
"provenance": [],
8+
"include_colab_link": true
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
}
14+
},
15+
"cells": [
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {
19+
"id": "view-in-github",
20+
"colab_type": "text"
21+
},
22+
"source": [
23+
"<a href=\"https://colab.research.google.com/github/tinhb92/relax_ml/blob/master/re.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"metadata": {
29+
"id": "ekTI5xEkc7Bt",
30+
"colab_type": "code",
31+
"colab": {}
32+
},
33+
"source": [
34+
"sentence = 'This is a sample string'"
35+
],
36+
"execution_count": 0,
37+
"outputs": []
38+
},
39+
{
40+
"cell_type": "code",
41+
"metadata": {
42+
"id": "iK6Tbp2DdHuo",
43+
"colab_type": "code",
44+
"colab": {}
45+
},
46+
"source": [
47+
"import re"
48+
],
49+
"execution_count": 0,
50+
"outputs": []
51+
},
52+
{
53+
"cell_type": "code",
54+
"metadata": {
55+
"id": "mYEKsxxcdt2O",
56+
"colab_type": "code",
57+
"colab": {
58+
"base_uri": "https://localhost:8080/",
59+
"height": 34
60+
},
61+
"outputId": "cef7c775-9d0c-4ffa-88cc-c6868ad9c27c"
62+
},
63+
"source": [
64+
"bool(re.search(r'is', sentence))"
65+
],
66+
"execution_count": 3,
67+
"outputs": [
68+
{
69+
"output_type": "execute_result",
70+
"data": {
71+
"text/plain": [
72+
"True"
73+
]
74+
},
75+
"metadata": {
76+
"tags": []
77+
},
78+
"execution_count": 3
79+
}
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"metadata": {
85+
"id": "KU6TNB2dem-_",
86+
"colab_type": "code",
87+
"colab": {}
88+
},
89+
"source": [
90+
""
91+
],
92+
"execution_count": 0,
93+
"outputs": []
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {
98+
"id": "INPkI4OCennu",
99+
"colab_type": "text"
100+
},
101+
"source": [
102+
"Search the string to see if it starts with \"The\" and ends with \"Spain\":\n",
103+
"\n"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"metadata": {
109+
"id": "YFwM54t3dwlS",
110+
"colab_type": "code",
111+
"colab": {}
112+
},
113+
"source": [
114+
"txt = \"The rain in Spain\"\n",
115+
"x = re.search(\"^The.*Spain$\", txt)"
116+
],
117+
"execution_count": 0,
118+
"outputs": []
119+
},
120+
{
121+
"cell_type": "code",
122+
"metadata": {
123+
"id": "h-YGvaFUeVeB",
124+
"colab_type": "code",
125+
"colab": {
126+
"base_uri": "https://localhost:8080/",
127+
"height": 34
128+
},
129+
"outputId": "075226dc-833a-4a53-c4fc-ded1f106d273"
130+
},
131+
"source": [
132+
"x"
133+
],
134+
"execution_count": 5,
135+
"outputs": [
136+
{
137+
"output_type": "execute_result",
138+
"data": {
139+
"text/plain": [
140+
"<_sre.SRE_Match object; span=(0, 17), match='The rain in Spain'>"
141+
]
142+
},
143+
"metadata": {
144+
"tags": []
145+
},
146+
"execution_count": 5
147+
}
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"metadata": {
153+
"id": "p4wTCELgehTd",
154+
"colab_type": "code",
155+
"colab": {
156+
"base_uri": "https://localhost:8080/",
157+
"height": 34
158+
},
159+
"outputId": "8e797049-caac-409b-a556-cf3e2236c890"
160+
},
161+
"source": [
162+
"x = re.findall(\"ai\", txt)\n",
163+
"print(x)"
164+
],
165+
"execution_count": 6,
166+
"outputs": [
167+
{
168+
"output_type": "stream",
169+
"text": [
170+
"['ai', 'ai']\n"
171+
],
172+
"name": "stdout"
173+
}
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"metadata": {
179+
"id": "a2oBDZdRe_gR",
180+
"colab_type": "code",
181+
"colab": {
182+
"base_uri": "https://localhost:8080/",
183+
"height": 34
184+
},
185+
"outputId": "74e7ebee-220b-4d78-cffe-368db479d841"
186+
},
187+
"source": [
188+
"x = re.search(\"\\s\", txt)\n",
189+
"\n",
190+
"print(\"The first white-space character is located in position:\", x.start())"
191+
],
192+
"execution_count": 7,
193+
"outputs": [
194+
{
195+
"output_type": "stream",
196+
"text": [
197+
"The first white-space character is located in position: 3\n"
198+
],
199+
"name": "stdout"
200+
}
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"metadata": {
206+
"id": "zx3OTK17fRxj",
207+
"colab_type": "code",
208+
"colab": {}
209+
},
210+
"source": [
211+
""
212+
],
213+
"execution_count": 0,
214+
"outputs": []
215+
}
216+
]
217+
}

0 commit comments

Comments
 (0)