Originally published byDev.to
Today I needed to group records by a substring contents of one of the columns. We have data like task_type: "Facade (S4)", so this should be grouped as belonging to group 4 (from S4).
Turns out there's a simple and powerful way to do this with regex-powered substring detection:
# SUBSTRING(string FROM pattern)
records.group(Arel.sql("SUBSTRING(task_type from 'S([0-9]+)$')"))
See docs.
🇺🇸
More news from United StatesUnited States
NORTH AMERICA
Related News
Secret Claude Tracker Shocks Users After Anthropic's Anti-Surveillance Stance
12h ago
EV Batteries Defy Expectations, Last Hundreds of Thousands of Miles
1d ago
GBase 8a Performance Anomaly Case Study: How a Single Parameter Change Sparked a Chain Reaction
1d ago
Who Else Has Inherited a Codebase With Zero Comments and a Prayer?
1d ago
完美的平庸
3h ago