Skip to content

Support "=" and "-" separators between an age keyword and its value #55

Description

@jzonthemtn

The age filter detects Age: 47 but not Age = 47 or Age - 47. The pattern in phileas/filters/age_filter.py allows only an optional colon:

re.compile(r"\b(age)(d)?(\s*:?\s*)[0-9.]+\b", re.IGNORECASE)

Java broadened this in philterd/phileas#332. Its separator is \s*(?:[:=-]\s*)?, which also accepts = and -, and keeps the whitespace inside the optional group so a run of whitespace can only be matched one way. The current \s*:?\s* has that same ambiguity: two adjacent \s* can split a whitespace run n+1 ways, so a non-matching input backtracks quadratically. SonarCloud flagged the equivalent Java expression as java:S8786.

Acceptance Criteria

  • Age = 47 and Age - 47 are detected, alongside the existing Age: 47
  • The separator may be omitted or surrounded by whitespace (Age:47, Age : 47, Age 47)
  • The whitespace may include a line break, so a label on one line with its value on the next is detected
  • Words ending in "age" are not matched (coverage: 47, mileage: 45000)
  • Dates such as 2026-01-15 are still not detected as ages
  • The separator group is rewritten so a whitespace run has only one possible match, removing the quadratic backtracking in the current \s*:?\s*
  • Tests cover the separator forms in tests/test_age_detection.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions