Skip to content

Commit b55a59e

Browse files
committed
Adding 0003-regex-findall.py
1 parent f766fa5 commit b55a59e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 0003-regex-findall.py
2+
3+
This script demonstrates the use of Python's `re.findall()` function to find all words in a given text that start with the letter "I".
4+
5+
## Description
6+
The script imports the `re` module (Python's regular expressions module) and uses `re.findall()` with the pattern `\bI\w+` to find all words that begin with the capital letter "I".
7+
8+
- `\b` asserts a word boundary, ensuring we only match words starting with "I".
9+
- `I` matches the literal capital letter "I".
10+
- `\w+` matches one or more word characters following "I".
11+
12+
The script runs two examples to demonstrate the regex:
13+
14+
1. Text: "The rain is happening in India"
15+
- Expected output: `["India"]`
16+
17+
2. Text: "The rain is happening in India and Ireland"
18+
- Expected output: `["India", "Ireland"]`
19+
20+
## Usage
21+
To run the script, you need Python 3 installed on your system. You can execute it using the following command:
22+
23+
```bash
24+
python 0003-regex-findall.py
25+
```
26+
27+
## Example Output
28+
```
29+
['India']
30+
['India', 'Ireland']
31+
```
32+
33+
## Dependencies
34+
- Python 3.x
35+
- `re` module (comes built-in with Python)
36+

0 commit comments

Comments
 (0)