Jinhong Park
Jinhong Park

Reputation: 45

Find in all text using the re.search in Python

Thank you for coming.

This is my code.

import re
content = '가나다라,456456 show, 가나다라<>'
a = re.search("[^a-zA-Z<>]+", content)
print(a.group())

Output : 가나다라,456456.

but I want this

Output : 가나다라,456456 , 가나다라

In other words, I want to search the full text . What can i do? :(

Upvotes: 0

Views: 42

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174796

You need to use re.findall in-order to get all the matches. re.search must return only the first match.

re.findall(r"[^a-zA-Z<>]+", content)

Example:

>>> import re
>>> content = '가나다라,456456 show, 가나다라<>'
>>> ''.join(re.findall("[^a-zA-Z<>]+", content))
'가나다라,456456 , 가나다라'

Upvotes: 1

Related Questions