#!/usr/bin/env python

#    python-regex - A simple implementation ot the python.re package
#    Copyright (C) 2017  Funilrys - Nissar Chababy <contact at funilrys dot com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

#    Original Version: https://github.com/funilrys/python-regex


from re import compile, search


class Regex(object):
    """A simple implementation ot the python.re package"""

    def __init__(self, data, regex, return_data=False, group=0):
        super(Regex, self).__init__()
        self.data = data
        self.regex = regex
        self.return_data = return_data
        self.group = group

    def match(self):
        """Used to get exploitable result of re.search"""

        if type(self.regex) is list and isinstance(self.data,str):
            result = []
            for item in self.regex:
                to_match = compile(item)
                local_result = to_match.search(self.data)

                if self.return_data and local_result is not None:
                    result.append(local_result.group(self.group))
                elif self.return_data == False and local_result is not None:
                    return True
            if self.return_data and result:
                return result
            return False
        elif type(self.data) is list and isinstance(self.Regex,str):
            result = []
            for item in self.data:
                to_match = compile(self.regex)
                local_result = to_match.search(item)

                if self.return_data and local_result is not None:
                    result.append(local_result.group(self.group))
                elif self.return_data == False and local_result is not None:
                    return True
            if self.return_data and result:
                return result
            return False
        elif isinstance(self.data,str) and isinstance(self.regex,str):
            toMatch = compile(self.regex)
            result = toMatch.search(self.data)

            if self.return_data and result is not None:
                return result.group(self.group).strip()
            elif self.return_data == False and result is not None:
                return True
            return False
        return None

@@ -17,19 +17,16 @@
 ython%0A%0A#
-   
  python-
@@ -83,19 +83,16 @@
 ackage%0A#
-   
  Copyrig
@@ -99,17 +99,16 @@
 ht (
-C
+c
 ) 2017 
- 
 Funi
@@ -167,409 +167,140 @@
 #%0A# 
-   This program is free software: you can redistribute it and/or modify%0A#    it under the terms of the GNU General Public License as published by%0A#    the Free Software Foundation, either version 3 of the License, or%0A#    (at your option) any later version.%0A#%0A#    This program is distributed in the hope that it will be useful,%0A#    but WITHOUT ANY WARRANTY; without even the implied warranty of%0A#   
+THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MER
@@ -315,11 +315,11 @@
 LITY
- or
+,%0A#
  FIT
@@ -351,222 +351,300 @@
 POSE
-.  See the%0A#    GNU General Public License for more details.%0A#%0A#    You should have received a copy of the GNU General Public License%0A#    along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E
+ AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A# SOFTWARE
 .%0A
+#
 %0A#
-   
  Ori
@@ -700,17 +700,16 @@
 -regex%0A%0A
-%0A
 from re 
@@ -761,16 +761,21 @@
 %0A    %22%22%22
+%0A    
 A simple
@@ -814,16 +814,21 @@
  package
+%0A    
 %22%22%22%0A%0A   
@@ -1137,19 +1137,25 @@
      if 
-typ
+isinstanc
 e(self.r
@@ -1158,25 +1158,23 @@
 lf.regex
-) is
+,
  list
+)
  and isi
@@ -1187,24 +1187,25 @@
 e(self.data,
+ 
 str):%0A      
@@ -1715,11 +1715,17 @@
 lif 
-typ
+isinstanc
 e(se
@@ -1735,17 +1735,15 @@
 data
-) is
+,
  list
+)
  and
@@ -1761,24 +1761,25 @@
 (self.Regex,
+ 
 str):%0A      
@@ -2306,16 +2306,17 @@
 lf.data,
+ 
 str) and
@@ -2338,16 +2338,17 @@
 f.regex,
+ 
 str):%0A  

Update license header + review some conditionals