Add regex and iregex lookups to filters for string fields #11394

Closed
opened 2025-12-29 21:44:34 +01:00 by adam · 2 comments
Owner

Originally created by @miaow2 on GitHub (Jul 17, 2025).

Originally assigned to: @miaow2 on GitHub.

NetBox version

v4.3.4

Feature type

Change to existing functionality

Proposed functionality

Now we have the following filter lookups for string fields in NetBox:

  • n
  • ic
  • nic
  • isw
  • nisw
  • iew
  • niew
  • ie
  • nie
  • empty

I want to add support for regex and iregex Django ORM lookups in filters for string fields.
It can be easily done by adding them to FILTER_CHAR_BASED_LOOKUP_MAP variable in netbox/utilities/constants.py.
I've tested this on my local NetBox deployment, and it's working well.

Use case

At my company, we have a specific naming convention, and in some cases, it's challenging to filter devices by name using existing lookups. Therefore, I propose this feature.

Also, regex and iregex are built-in Django ORM lookups, and PostgreSQL fully supports them.
Now, only GraphQL supports these lookups, adding regex lookups will make filtering in other interfaces more consistent.

If the feature is accepted, you can assign it to me, and I will make a PR with updates for code, tests, and docs.

Database changes

No database changes

External dependencies

No response

Originally created by @miaow2 on GitHub (Jul 17, 2025). Originally assigned to: @miaow2 on GitHub. ### NetBox version v4.3.4 ### Feature type Change to existing functionality ### Proposed functionality Now we have the following filter lookups for string fields in NetBox: * n * ic * nic * isw * nisw * iew * niew * ie * nie * empty I want to add support for `regex` and `iregex` Django ORM lookups in filters for string fields. It can be easily done by adding them to `FILTER_CHAR_BASED_LOOKUP_MAP` variable in [netbox/utilities/constants.py](https://github.com/netbox-community/netbox/blob/main/netbox/utilities/constants.py#L5C1-L5C30). I've tested this on my local NetBox deployment, and it's working well. ### Use case At my company, we have a specific naming convention, and in some cases, it's challenging to filter devices by name using existing lookups. Therefore, I propose this feature. Also, `regex` and `iregex` are built-in Django ORM lookups, and PostgreSQL fully supports them. Now, only GraphQL supports these lookups, adding regex lookups will make filtering in other interfaces more consistent. If the feature is accepted, you can assign it to me, and I will make a PR with updates for code, tests, and docs. ### Database changes No database changes ### External dependencies _No response_
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:44:34 +01:00
adam closed this issue 2025-12-29 21:44:34 +01:00
Author
Owner

@miaow2 commented on GitHub (Jul 18, 2025):

I am happy to contribute this feature.
Please let me know if you would like me to submit a PR.

@miaow2 commented on GitHub (Jul 18, 2025): I am happy to contribute this feature. Please let me know if you would like me to submit a PR.
Author
Owner

@jeremystretch commented on GitHub (Jul 18, 2025):

@miaow2 all yours, thanks!

@jeremystretch commented on GitHub (Jul 18, 2025): @miaow2 all yours, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11394