Skip to content

Commit bb2ea04

Browse files
authored
Update README.md
1 parent 7352187 commit bb2ea04

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ time.sleep(SECONDS_IN_A_DAY)
8282
**Bad:**
8383
```python
8484
address = 'One Infinite Loop, Cupertino 95014'
85-
city_zip_code_regex = r'/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/'
86-
preg_match($cityZipCodeRegex, $address, $matches);
85+
city_zip_code_regex = '^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$'
86+
matches = re.match(city_zip_code_regex, address)
8787

88-
saveCityZipCode($matches[1], $matches[2]);
88+
save_city_zip_code(matches[1], matches[2])
8989
```
9090

9191
**Not bad**:
9292

9393
It's better, but we are still heavily dependent on regex.
9494

95-
```php
96-
$address = 'One Infinite Loop, Cupertino 95014';
97-
$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/';
98-
preg_match($cityZipCodeRegex, $address, $matches);
95+
```python
96+
address = 'One Infinite Loop, Cupertino 95014'
97+
city_zip_code_regex = '^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$'
98+
matches = re.match(city_zip_code_regex, address)
99+
100+
city, zip_code = matches.groups()
99101

100-
list(, $city, $zipCode) = $matches;
101-
saveCityZipCode($city, $zipCode);
102+
save_city_zip_code(city, zip_code)
102103
```
103104

104105
**Good**:

0 commit comments

Comments
 (0)