Question: I get some data from the database, which is saved in "$Data". $Data looks like this:

```
        [Data] => Array
            (
                [0] => Array
                    (
                        [PrinterID] => 3
                        [PrinterName] => PRT03_EDV
                        [isDefaultPrinter] => 1
                        [isMapped] => 0
                    )

                [1] => Array
                    (
                        [PrinterID] => 1
                        [PrinterName] => PRT01_Zentral
                        [isDefaultPrinter] => 0
                        [isMapped] => 1
                    )

                [2] => Array
                    (
                        [PrinterID] => 2
                        [PrinterName] => PRT02_BH
                        [isDefaultPrinter] => 0
                        [isMapped] => 0
                    )

```

I need to verify, that there is no array in $Data, where "isDefaultPrinter == True" and "isMapped == False". Programatically:

```
if ( $Data["isDefaultPrinter"] == true and $Data["isMapped"] == false ) {
  // Remove from Array
}

```

I did start to code this on my own based on [this](https://stackoverflow.com/questions/2304570/how-to-delete-object-from-array-inside-foreach-loop) and my result was a terrible looking nested loop, which did not work :-(  

I am a beginner and I wanted to ask, if there is an nice and easy way to do this?

Thank you

Answer: 
for your requirement, just match all 4 digit numbers

```python
import re
s = '''1970 - 1980
January 1920 - Feb 1930
May 1920 to September 1930
July 1945'''

p = re.compile(r'\b\d{4}\b')

s = s.splitlines()
for x in s:
    result = p.findall(x) 
    print(result)

```

output

```python
['1970', '1980']
['1920', '1930']
['1920', '1930']
['1945']

```
**Regex**: [`.*?([0-9]{4})(?:.*?([0-9]{4}))?`](https://regex101.com/r/dWTulg/2) or `.*?(\d{4})(?:.*?(\d{4}))?`

Details:

* `()` Capturing group
* `(?:)` Non capturing group
* `{n}` Matches exactly `n` times
* `.*?` Matches any char between zero and unlimited times (lazy)

**Python code**:

```
def Years(text):
        return re.findall(r'.*?([0-9]{4})(?:.*?([0-9]{4}))?', text)

print(Years('January 1920 - Feb 1930'))

```

Output:

```
[('1920', '1930')]

```