Skip to content

Commit 1083247

Browse files
Update README.md
1 parent 1829b14 commit 1083247

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,17 @@ $ Matches the end of the line
9292
( Indicates where string extraction is to start
9393
) Indicates where string extraction is to end
9494
```
95+
### Usage in Python:
96+
```python
97+
#re.search()- check if a string matches a regular expression
98+
#re.findall()- extract portions of string that matches our regular expressions
99+
100+
import re
101+
hand=open('text.txt')
102+
for line in hand:
103+
line=line.rstrip()
104+
if re.search('^From:',line)
105+
print(line)
106+
107+
EX--> ^X.*: --> starts with X, followed by 1 or more (due to +) non-blank characters (due to \S) and then ':'
108+
```

0 commit comments

Comments
 (0)