
Tag: Regex
Dive into our extensive collection of articles on Regex, showcasing various tips, tricks, and tutorials to master Regular Expressions for pattern matching, data validation, and text manipulation across multiple programming languages.


Parsing SOAP XML Response In Python
In this tutorial, you will learn how to decode and parse a large SOAP XML response with Python and regular expression, essentially the goal here was to build a Python function to get rid of manually decoding SOAP XML response over and over again.
The Python code I’m about to explain and show you was developed as a part of refund payment integration done in Python and Django.
We’re going to take a look at an encoded SOAP XML response stdout saved in a text file.
I saved this SOAP response output when I was in a process of developing a payment integration feature for a local bank here in Riga, Latvia, along the way I realized it’s going to be a great learning experience for anyone else who’s going to search for a similar solution on Google.
I’ve discussed similar text file parsing in Python situations before here on the blog, but the difference here is that this one is way more complicated and involves a bit more decoding and text manipulation as well as extensive knowledge on regex pattern matching.
Definitely a good Python regular expression practice, even for advanced Python developers.
Currently, I’m working as a Python Django backend developer (Roberts Greibers) for a local company here in Riga, Latvia – building a white-label payment gateway platform, you can find more about my experience on my Linkedin profile
Give me a follow on Linkedin or send me a DM if you have any questions.
One of the recent payment integration flows I needed to develop was for a refund payment. Refund payments were supposed to work for multiple banks through one gateway system for this particular client and brand.
The whole refund payment flow is way more complicated and would take me weeks to write up and explain here on the blog so I’m gonna share a small portion of what actually was very interesting to work on – parsing decoded SOAP XML response with regular expression in Python.
I go deeper explaining features you can develop for your Python and Django portfolio if you’re working personally with me in one on one Zoom calls (click here to see an example of a LIVE Zoom call). I personally will guide you through the development of each feature and answer all your questions along the way.
This is what we’re working on with my most successful mentoring clients.
So if the above sounds interesting, let’s get started!
Continue reading
Log File Parsing In Python
Here’s a YOUTUBE VIDEO version of this blog post, check it if you’re looking for a quick solution to build your own Log File Parsing Tool in Python. ππ»
In this tutorial, you will learn how to open a log file, read a log file, and create a log file parser in Python, essentially building a so-called “Python log reader”.
To open a log file in Python, read a log file, and actually parse a log file or any type of text file in order to extract specific information is not that hard if you know a bit of Python log file parsing and regex pattern match usage.
Python itself is a perfect tool to open a log file for parsing and it does not require any third-party modules. Believe me, the first thing I did was a Google search for a “Python log reader” and “Python file parsing” a couple of years ago when I first started to work on parsing text files in Python. Ever since those days, I’ve learned to work with Python and regex very efficiently, see more details in a recent post I did about how to parse XML SOAP response with Python and regex by clicking here.
In my day job, a while back I was working on testing Skype for Business iOS application as a test engineer and it came to the point where I had to open and manually collect the SfB iOS application log files in order to see all HTTP requests and received HTTP responses.
Ever since then I’ve switched to backend development with Python/Django and also helped people to go into a similar path. See a cut from a recent coaching call here. And more about client testimonials here.
Anyways, in this specific situation, I had to figure out a good way to open iOS log files and parse them to search a log file for properties like:
<code><property name="saveMessagingHistory">Enabled</property></code>
Usually, properties were buried under a bunch of other not-so-important log file dumps, for example:
INFO UTILITIES /Volumes/ServerHD2/buildagent/workspace/200615/client_ios_sfb/dependencies/client-shared_framework_sfbplatform/src/dev/lyncMobile/platform/tracing/privateIos/CMTrace.mm/173:Version Information 6.12.0.65
2016-12-20 13:16:52.303 SfB[417:1af74bc40] INFO UTILITIES CTimer.cpp:657 TimerMap is created
2016-12-20 13:16:52.342 SfB[417:1af74bc40] INFO UI SFBAppDelegate.mm:69 Application will finish launching with options
2016-12-20 13:16:52.345 SfB[417:1af74bc40] INFO UTILITIES CStorageManager.mm:146 Creating StorageManager
2016-12-20 13:16:52.347 SfB[417:1af74bc40] INFO UTILITIES CStorageManager.mm:187 Initializing StorageManager
2016-12-20 13:16:52.357 SfB[417:1af74bc40] INFO APPLICATION CApplication.cpp:3400 Initialize Internal Begin
2016-12-20 13:16:52.361 SfB[417:1af74bc40] INFO UTILITIES COsInformation.mm:398 User UI language identifier en was mapped to en-US 1033
2016-12-20 13:16:52.362 SfB[417:1af74bc40] INFO UTILITIES COsInformation.mm:106 Device Version Info - Model=iPhone, HardwareModel=iPhone9,3, SystemName=iOS, SystemVersion=10.1
2016-12-20 13:16:52.362 SfB[417:1af74bc40] VERBOSE APPLICATION CApplication.cpp:3415 Initialize Internal -- App State Query Established
2016-12-20 13:16:52.363 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:70 Successfully started listening to network events
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:229 Reachabilility Flags IsWWAN(0):Reachable(1):TransientConnection(0):ConnectionRequired(0):ConnectionOnTraffic(0):InterventionRequired(0):ConnectionOnDemand(0):IsLocalAddress(0):IsDirect(0)
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:198 Updated networkAvailableToConnect(NoNetwork) -> WiFi, isInAirplaneMode(0) -> 0
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CTimer.cpp:227 Created timer instance (0x70286428) for runloop (0x7017e780)
While I was searching for specific properties in those log files, I realized itβs going to be really time-consuming to go through everything manually.
In order to save time, I had to come up with a good way to use Python file parsing, and long behold I managed to write code for a log file parsing Python script.
It’s a very simple way of searching a log file with Python.
If you want to test the following Python log parsing script with a similar text file, you have to download Skype for Business iOS log file here:
Continue reading