This can be simplified by using string.split.
```python
'1.2.3.4.5'.split('/', 1)[0]
'1.2.3.4.5/64'.split('/', 1)[0]
```