The most occurring number in a string using Regex in python
Given a string str, the task is to extract all the numbers from a string and find out the most occurring element of them using Regex Python.
- It is guaranteed that no two element have the same frequency
Input :geek55of55geeks4abc3dr2 Output :55 Input :abcd1def2high2bnasvd3vjhd44 Output :2
Approach:Extract all the numbers from a string str using re.findall() function from regex library in python, and with the use of Counter function from collection library we can get the most occurred element.
Below is the Python implementation of above approach