rohit nair rohit nair - 2 years ago 80
Python Question

How to get the the required data from a string using Regexp or any string manipulation method

I have many Json responses from an instagram API which contains data like this:-

Answer Source

This regex seems to do an acceptable job:

(?i)([\w.]+@[\w.]+)|(?:(?:\b|[,/]\s*)(?:whatsapp|viber|wechat))+\b\s*[::]?\s*([()+\d -]+)|\bline(?:\sid)?\s*(?:[::]\s*)?(@\w+)|((?:\+\d+)?[ -]?(?:\(\d+\)[ -]?)?[\d -]{6,}\d)


This captures emails in capture group 1, Whatsapp/Viber/Wechat numbers in group 2, and line IDs in group 3.

Usage example:

import re

text= '
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download