Simple text-filtering examples in OPAL (token search, regex, starts_with)

Summary

Short, copy-ready examples demonstrating common text-filtering patterns in OPAL:

  • Token search (~)

  • Regex (match_regex or regex literals)

  • Prefix checks (starts_with)

Examples use this sample dataset (one row per line; headers shown):

product_barcode,product_desc
1,1 lb. bag of Apples
2,"fruit salad (apples,oranges,bananas,strawberries)"
3,1 quart of Strawberries
4,canteloupe
5,watermelon
5,sliced apples and caramel
6,"strawberries,blueberries, and raspberries"


Official Documentation


Examples

Column names: product_barcode, product_desc

1. Token / Keyword Search (case-insensitive)

filter product_desc ~ apple

Matches:

  • 1 — 1 lb. bag of Apples

  • 2 — fruit salad (apples,oranges,bananas,strawberries)

  • 5 — sliced apples and caramel

Why: ~ performs tokenized, case-insensitive keyword search.
(See Unified Search docs.)


2. Regex Literal (case-insensitive)

filter product_desc ~ /apple/i

Matches: same as above.
Why: Use regex literals when you need regex syntax plus inline flags.
(See Unified Search / Search Syntax.)


3. Regex Function with Explicit Flags

filter match_regex(product_desc, /apple/, 'i')

Matches: same as #1 and #2.
Why: match_regex is useful for programmatic flag control or function-style expressions.
(See match_regex docs.)


4. Case-Sensitive Regex (no 'i' flag)

filter match_regex(product_desc, /apple/)

Matches: only lowercase “apple” entries, such as:

  • 2 — fruit salad (apples,oranges,bananas,strawberries)

  • 5 — sliced apples and caramel

(See OPAL case-sensitivity notes and match_regex docs.)


5. Prefix / starts_with (case-sensitive)

filter starts_with(product_desc, "canteloupe")

Match:

  • 4 — canteloupe

Case-Insensitive Variant

make_col pd_lower: lower(product_desc)
filter starts_with(pd_lower, "canteloupe")

Why: starts_with is case-sensitive; use lower() to normalize for case-insensitive matching.
(See OPAL string functions.)


Extra Tips & Pitfalls

  • Prefer ~ apple for simple, case-insensitive token searches.

  • Use regex (match_regex or /.../) for anchors, classes, or punctuation-aware matches.

  • Apply lower() or similar normalization when using case-sensitive string functions.