'Regex to split text with hyphen points
Suppose that we have the following string:
'We need the list fo the following products: - Abcd efgh ejklm - Efgh-ij sklrm, defasad - KLMNNOP/QRS dasfdssa eadsd'
I want a regex that return:
- Abcd efgh, ejklm
- Efgh-ij sklrm, defasad
- KLMNNOP/QRS dasfdssa eadsd
I write this one that works correctly but it cuts if we have a composed word.
import re
regx = '-\s[\w\s\/?,;!:#&@]*' # start with hyphen + space + mix of different characters
z = re.findall(regx, 'We need the list fo the following products: - Abcd - Efgh-ij - KLMNNOP/QRS')
for p in z:
print(p)
- Abcd efgh, ejklm
- Efgh
- KLMNNOP/QRS dasfdssa eadsd
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
