Question: I have the following regex that I am using to match on various credit card numbers within a string search of files. However, if there is a space before or after the pattern to match, then the match will fail.

```
$CC_Regex = "^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$"

```

For example, it will match the top three, but will not match the bottom three.

```
1111-2323-2312-3434
1234343425262837
1111 2323 2312 3434

1111-2323-2312-3434 
 1234343425262837
 1111 2323 2312 3434 

```

Out of the bottom three, the first one has a space at the end of it, the second one has a space before it, and the third one has a space before and after it.

Thanks in advance for your help.

Answer: 
```
$CC_Regex = "^\s*(\d{4}-){3}\d{4}\s*$|^\s*(\d{4} ){3}\d{4}\s*$|^\s*\d{16}\s*$"

```

will make it match even if leading or trailing whitepsace is present (`\s` means any whitespace character).
```
$CC_Regex = "(?:\d{4}[- ]?){3}\d{4}"

```