python
12 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
import re
text = 'INC-102301 resolved on 2026-04-06 after payment failure for order ORD-99182.'
patterns = {
'incident_id': r'INC-[0-9]{6}',
'order_id': r'ORD-[0-9]{5}',
'date': r'\b\d{4}-\d{2}-\d{2}\b',
}
extracted = {name: re.findall(pattern, text) for name, pattern in patterns.items()}
print(extracted)
1 file · python
Explain with highlit
Regex is not glamorous, but it remains one of the fastest ways to turn messy text into useful structured fields. I use it for IDs, dates, codes, and log fragments before reaching for heavier NLP. The important part is making patterns specific enough to avoid silent false positives.
Related snips
python
import pandas as pd
df = pd.read_csv('customers.csv')
df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_', regex=False)
Cleaning missing values and normalizing messy CSV exports
pandas
data-cleaning
missing-values
by Dr. Elena Vasquez
1 tab
python
from defusedxml.ElementTree import fromstring
payload = request.data.decode('utf-8')
root = fromstring(payload)
invoice_number = root.findtext('invoice_number')
XXE safe XML parsing with external entity resolution disabled
xxe
xml
parsing
by Kai Nakamura
1 tab
ruby
# Basic matching
email = "user@example.com"
email =~ /@/ # => 4 (position of match)
email.match?(/@/) # => true
# Capture groups
Regular expressions for pattern matching
ruby
regex
regular-expressions
by Sarah Mitchell
3 tabs
rust
use std::collections::HashMap;
#[derive(Debug, PartialEq)]
pub enum LogLevel {
Info,
Warn,
Streaming Log File Aggregation With Buffered Line Iteration in Rust
rust
streaming
file-io
by codesnips
3 tabs
swift
import Foundation
// MARK: - Basic Codable
struct User: Codable {
let id: Int
let username: String
JSON encoding and decoding with Codable
swift
codable
json
by Sofia Martinez
1 tab
python
from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Dict, List
Parsing a Nested JSON Feed into Normalized Dataclasses in Python
dataclasses
json
parsing
by codesnips
3 tabs
Share this code
Here's the card — post it anywhere.