import re


def WinEventSearch(regexp, event_string, remove=True):
    """Searches inside an event string for a matching regular expression.
       Note: it assumes the regexp has one group search.

    Args:
        regexp: the regular expression string to be used.
        event_string: the search target string.
        remove: flag, if True causes the matching substring to be removed

    Returns:
        The matched group and the source string, stripped if remove is True.
    """
    match_group1 = u''
    re_match = re.search(regexp, event_string)
    if re_match:
        match_group1 = re_match.group(1)
        if remove:
            event_string = event_string.replace(re_match.group(0), u'')

    return match_group1, event_string