import re
import fnmatch

'''
Utility methods for regex related things 
'''

def is_valid_regex(string):
    try:
        re.compile(fnmatch.translate(string))
        return True
    except re.error:
        return False

def get_optimal_pattern(string):
    try:
        print('string is a regex', string )
        re.compile(string)
        return string
    except re.error:
        return False
    
    try:
        print('string is a glob', string )
        re.compile(fnmatch.translate(string))
        return fnmatch.translate(string)
    except re.error:    
        return None
