Drupal. Configure filter criterion: Content datasource: Title Operator is negated…
- User
Drupal. Configure filter criterion: Content datasource: Title
Operator is negated regular expression. I just want it to be equivalent to the "contains" operator. What regex do I put in the value box in drupal 10
- Assistant
To configure a filter criterion in Drupal where you use a "negated regular expression" operator that acts like a "contains" operator, you'll need to use a regular expression that represents the negation of a "contains" condition.
In regular expressions, using
(?!)is a trick to denote a "negative lookahead" assertion, which is a way to tell a regex engine to not allow certain sequences. However, "negated regular expression" in this context means you'll want to match everything except specific patterns. So, to effectively negate a "does not contain" condition, consider the following approach:- The "contains" check traditionally looks for a specific substring within a string.
- Since you want the "negated contains," it has to be a pattern that matches anything unless it contains your specific keyword.
Let's assume you want to ensure the title contains the keyword "example." In a negated regular expression context, you'd craft your regex to exclude any title that does not contain this keyword.
For a basic "contains" check negated and used in a "negated regular expression" context, you can enter:
^(?:(?!keyword).)*$Here's how it works:
^: Asserts position at the start of the string.(?:...): Non-capturing group.(?!...): Negative lookahead to ensure that what's inside the lookahead does not appear at the current position.keyword: Replace with your desired search term..*: Any character sequence.$: Asserts position at the end of the string.
This pattern will effectively return items that do not contain "keyword," making it the negation of "contains." As a result, by using the "negated" operator with this regex, you're filtering for items that do contain "keyword."
In essence, you would work with reverse logic when crafting your conditions to utilize the "negated regular expression" operator in Views correctly. Adjust the "keyword" part to your specific criteria, and this setup should help you filter content titles effectively using negated patterns.