# Run2 Scala Text Processing

> Robust text tokenization with regex and position tracking in Scala.

- Skill: `cxcscmu/run2-scala-text-processing` (Agent Skill)
- Install (CLI): `npx get-skill add cxcscmu/run2-scala-text-processing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cxcscmu/run2-scala-text-processing/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: cxcscmu (https://skillmd.com/u/cxcscmu)
- Updated: 2026-11-24
- Page: https://skillmd.com/skills/cxcscmu/run2-scala-text-processing

---


# Text Tokenization in Scala

Scala `String` methods like `split` and `replaceAll` are available.

## Regex Splitting
```scala
val words = text.split("\\s+").filter(_.nonEmpty)
```

## Position Tracking
Find positions using `indexOf`.

```scala
def tokenizeWithPos(text: String): List[(String, Int, Int)] = {
  val words = text.split("\\s+").filter(_.nonEmpty)
  var curr = 0
  words.map { w =>
    val start = text.indexOf(w, curr)
    val end = start + w.length
    curr = end
    (w, start, end)
  }.toList
}
```

## Character Sets
Scala's `Set[Char]` and `exists` for char-level operations.
Using `dropWhile` and `reverse.dropWhile` for trimming custom character sets.

