lundi 7 juin 2021

Python matching strings within substrings

I'm writing a program to take a json formatted file and create a proxy PAC file. One of the challenges I've encountered is that the json file contains a mixture of data which is not neatly organized. I would like to summarize the data like so:

Input data:

www.example.com
*.example.com
example.com
myserver.example.com
server.*.example2.com
server.mydomain1.example2.com
server.mydomain2.example2.com
server.mydomain3.example2.com
example2.com

Output data:

*.example.com
example.com
server.*.example2.com
example2.com

I'm trying to find the most python way to summarize the data. Any ideas? I thought of using regular expressions to help with pattern matching but I imagine they can get complicated quite quickly?

Aucun commentaire:

Enregistrer un commentaire