def regex_search(value, regex, *args, **kwargs):
 groups = list()
 for arg in args:
  if arg.startswith('\\g'):
   match = re.match('\\\\g<(\\S+)>', arg).group(1)
   groups.append(match)
  elif arg.startswith('\\'):
   match = int(re.match('\\\\(\\d+)', arg).group(1))
   groups.append(match)
  else:
   raise errors.AnsibleFilterError('Unknown argument')
 flags = 0
 if kwargs.get('ignorecase'):
  flags |= re.I
 if kwargs.get('multiline'):
  flags |= re.M
 match = re.search(regex, value, flags)
 if match:
  if (not groups):
   return match.group()
  else:
   items = list()
   for item in groups:
    items.append(match.group(item))
   return items

def regex_search ( value , regex , * args , ** kwargs ) : groups = list ( ) for arg in args : if arg . startswith ( '\\g' ) : match = re . match ( '\\\\g<(\\S+)>' , arg ) . group ( 1 ) groups . append ( match ) elif arg . startswith ( '\\' ) : match = int ( re . match ( '\\\\(\\d+)' , arg ) . group ( 1 ) ) groups . append ( match ) else : raise errors . AnsibleFilterError ( 'Unknown argument' ) flags = 0 if kwargs . get ( 'ignorecase' ) : flags |= re . I if kwargs . get ( 'multiline' ) : flags |= re . M match = re . search ( regex , value , flags ) if match : if ( not groups ) : return match . group ( ) else : items = list ( ) for item in groups : items . append ( match . group ( item ) ) return items
perform re .