Metadata-Version: 2.4
Name: py-incl-excl-regex
Version: 0.1.0
Summary: Regex-based inclusion/exclusion filter loaded from JSON config
License: MIT License
        
        Copyright (c) 2026 Avishek Sen Gupta
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# py-incl-excl-regex

Regex-based inclusion/exclusion filter for Python.

## Install

```bash
pip install py-incl-excl-regex
```

## Quick start

```python
from incl_excl_regex import PatternFilter

f = PatternFilter(
    include=[r"sg\.gov\.sla"],
    exclude=[r"\.to(\.|$)", r"\.dao(\.|$)"],
)

f.matches("sg.gov.sla.stars.service.FooService")  # True
f.matches("sg.gov.sla.stars.to.FooTo")            # False — excluded
f.matches("com.example.Bar")                       # False — not included
```

## Filter rules

- **Include list**: a value must match at least one include pattern to pass. Omitting include patterns accepts everything.
- **Exclude list**: a value must not match any exclude pattern.
- **Exclude wins**: if a value matches both an include and an exclude pattern, it is rejected.
- Patterns are matched with `re.search` — the pattern can match anywhere in the string.

## Loading from a JSON file

```python
f = PatternFilter.from_file("filter.json")
```

Expected JSON shape (both keys are optional):

```json
{
  "include": ["sg\\.gov\\.sla"],
  "exclude": ["\\.to(\\.|$)", "\\.dao(\\.|$)"]
}
```

## Anchoring

Patterns use `re.search`, so they match anywhere in the string by default. Use `^` and `$` anchors when you need to match from the start or end:

```python
PatternFilter(include=[r"^sg\.gov\.sla"])   # must start with sg.gov.sla
PatternFilter(exclude=[r"\.to$"])            # only rejects strings ending in .to
```
