Python Regex, Find All Matches With Pattern
I'm trying to work with Slack's API and it sends a character string for user names, for instance: <@UCH65RHRC> Therefore, in the API JSON body's text, there could be several
Solution 1:
This is a very straightforward task. The regular expression <@([0-9A-Z]{9})>
should meet your requirement. For example:
import re
body = "Hi <@UCH65RHRC> and <@UCH65RHRF>, thanks for all the great work!"
id_search = re.findall("<@([0-9A-Z]{9})>", body)
foridin id_search:
print(id)
This will provide the following output:
UCH65RHRC
UCH65RHRF
Post a Comment for "Python Regex, Find All Matches With Pattern"