top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,080 per month

Why "Matches Regex" and "Matches Pattern" Might Not Be Best Practices



In the world of ServiceNow, efficiently filtering data is crucial for various tasks, from configuring reference fields in Record Producers to building dynamic reports. You might have stumbled upon the "matches regex" or "matches pattern" operators, seemingly powerful tools for advanced filtering. However, before you rely heavily on these options, it's important to understand their limitations and potential pitfalls within the ServiceNow platform. This article will shed light on why these operators can be problematic and guide you towards more robust and reliable alternatives for your ServiceNow filtering needs.


If you've tried using the "matches regex" or "matches pattern" operators in ServiceNow, particularly within condition builders or reference qualifiers, you might have encountered unexpected errors, often related to SQL or MySQL. You're not alone. Many ServiceNow users have reported similar issues, and there's a good reason for this.


The Problematic Nature of "matches regex" and "matches pattern"


The truth is, these operators in ServiceNow have a history of being unreliable and prone to causing errors. In fact, it's a known issue within the platform, and the recommendation from ServiceNow itself is generally to avoid using them. You might wonder why these options are even available if they are not dependable. This is a valid question, and unfortunately, the answer isn't straightforward. These features have lingered within the platform despite their instability.


Why Do Errors Occur?


The underlying reasons for the issues with these operators are tied to how ServiceNow interacts with its database when these conditions are applied. While the exact technical details are complex, the outcome is often SQL or MySQL errors that prevent your filters from working as expected. This can lead to frustration and delays in achieving your desired results.


Troubleshooting: The Best Approach is Avoidance


When it comes to "matches regex" and "matches pattern," traditional troubleshooting steps are often futile. No matter how carefully you construct your regular expression or pattern, the underlying issues within the ServiceNow implementation can still lead to errors. Therefore, the most effective "troubleshooting" strategy is to steer clear of these operators altogether.


Reliable Alternatives for Advanced Filtering


Fortunately, ServiceNow offers several robust and dependable alternatives for achieving complex filtering requirements:

  • Script Includes with Reference Qualifiers

     For filtering reference fields dynamically, using a Script Include in your reference qualifier is a powerful and recommended approach. You can write JavaScript code within the Script Include to perform intricate filtering logic, including leveraging JavaScript's built-in regular expression capabilities.

    • Example: Let's say you need to filter a list of servers based on the 5th and 6th characters of their names, as in the original community post. You could create a Script Include with a function that retrieves all active servers and then iterates through them. Within the loop, you can use JavaScript's substring() method to extract the 5th and 6th characters of the server name and compare them against your desired pattern using a regular expression. Finally, the function would return a GlideRecord query that filters the server table based on this logic.

  • Standard Query Operators

    For many filtering needs, the standard ServiceNow query operators like "contains," "starts with," "ends with," "is," "is not," and others are sufficient and far more reliable. Consider if your filtering requirements can be met using these built-in options before resorting to more complex methods.


Practical Use Case: Filtering Server Names (Revisited)


Instead of trying to use "matches regex" or "matches pattern" directly in the reference qualifier, you can achieve the goal of filtering server names based on specific positions using a Script Include. The Script Include would contain a function that performs the following:

  1. Query the cmdb_ci_server table (or the appropriate server table in your instance).

  2. Iterate through the records.

  3. For each record, extract the substring representing the 5th and 6th characters of the server name.

  4. Check if this substring matches the desired pattern (e.g., "SN", "sn", etc.).

  5. Build a query string containing the sys_ids of the servers that meet the criteria.

  6. Return this query string to the reference qualifier.

This approach provides a much more stable and controllable way to implement your filtering requirements.


Conclusion


While the "matches regex" and "matches pattern" operators might seem like convenient options for advanced filtering in ServiceNow, their history of instability and the recommendation against their use make them unreliable choices. Instead, leverage the power and flexibility of Script Includes within reference qualifiers or utilize the standard, dependable query operators provided by ServiceNow. By adopting these alternative solutions, you can ensure more accurate and error-free data filtering within your ServiceNow environment, ultimately leading to more efficient and effective workflows.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,080 per month

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page