I love using Python and I also love using it with Regex.
Searching for a word and enabling case insensitive matching with a flag.
```python
In [1]: import re
In [2]: to_read = 'How to read.'
In [4]: bool(re.search(r'how', to_read))
Out[4]: False
In [5]: bool(re.search(r'how', to_read, flags=re.I))
Out[5]: True
```
## re.search
*Searching for a pattern in a string.*
==re.search(pattern, string, flags=0): Checks if the pattern is present anywhere in the string17 . It returns a re.Match object if found, and None otherwise.==
==re.search() in Conditional Expressions: re.Match objects evaluate to True and None evaluates to False in a boolean context11 . This allows direct use in if or while statements11 .==
```python
import re
def search():
text = "Python regex is awesome!."
pattern = "regex"
match = re.search(pattern, text)
if match:
print(f"Located '{pattern}' in the text at position of {match.start()}")
else:
print(f"'{pattern}' not found.")
```
**Explanation:**
- We first `import` the `re` library to use its functions.
- We define a `text` string and a `pattern` we want to find.
- `re.search(pattern, text)` tries to find the first occurrence of the `pattern` ("regex") within the `text`.
- If a match is found, the `search()` function returns a match object; otherwise, it returns `None`.
- The `if match:` block checks if a match object was returned.
- If there's a match, `match.start()` gives us the starting index of the matched pattern in the `text`