...

/

Solution Explanations: Regular Expressions

Solution Explanations: Regular Expressions

Review solution explanations for the code challenges on regular expressions.

Solution 1: Shorthand character classes

Here’s the solution:

Press + to interact
Python 3.8
Files
import pandas as pd
import re
ip_addresses_df = pd.read_csv('practice_logs.csv')
ip_addresses_df = ip_addresses_df['LogText'].str.extract(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
print(ip_addresses_df)

Let’s go through the solution explanation:

  • Line 5: We extract IP addresses using the r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' regular expression that ...