For a given string str , the challenge is to extract all the numbers from the string and figure out the most common element using Regex Python.
- Guaranteed, that no two elements have the same frequency
- Examples :
Input: geek55of55geeks4abc3dr2 Output: 55 Input: abcd1def2high2bnasvd3vjhd44 Output: 2
Approach: Extract all numbers from string str , using the re.findall () function from the regex library in python, and using the Counter function from the collection library we can get the most common element.
Below is an implementation of the above Python approach.
< code class = "undefined spaces">