Context
I'm parsing some code and want to match the doxygen comments before a function. However, because I want to match for a specific function name, getting only the immediately previous comment is giving me problems.
Current Approach
import re
function_re = re.compile(
r"\/\*\*(.+)\*\/\s*void\s+(\w+)\s*::\s*function_name\s*\(\s*\)\s*")
function_match = function_re.search(file_string)
if function_match:
function_doc_str = update_match.group(2)
Problem with Current Approach
The current approach matches doxygen from earlier functions, giving me a result that is the wrong doxygen comment.
Question
Is there a way to search backward through a string using the Python Regex library?
It seems like my problem is that the more restrictive (less frequently occurring part) is the function signature, "void function()"
Possible better question
Is there a better (easier) approach that I'm missing?