apple-text-parsing

Compare Swift Regex and NSRegularExpression and bridge match ranges to NSRange for TextKit workflows.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sitapix/apple-text --skill apple-text-parsing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: apple-text-parsing
Source: https://github.com/sitapix/apple-text/tree/main/skills/apple-text-parsing
Command: npx skills add https://github.com/sitapix/apple-text --skill apple-text-parsing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers decide when to use Swift Regex versus NSRegularExpression, and explains how to bridge regex results to NSRange for TextKit-based editing, improving accuracy and performance decisions.

Core Features & Use Cases

  • Clear guidance on choosing between Swift Regex, RegexBuilder, and NSRegularExpression for text parsing in iOS apps.
  • Practical bridging strategies to map Range<String.Index> to NSRange for TextKit / NSAttributedString workflows.
  • Best-practice considerations for performance, deployment targets (iOS 16+ for Swift Regex), and interoperability with Foundation parsers.

Quick Start

Compare a sample Swift Regex and NSRegularExpression pattern for a text snippet and show how to bridge the match ranges to NSRange in a TextKit context.

Frequently Asked Questions about apple-text-parsing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I bridge Swift Regex match results to NSRange for TextKit workflows?

To bridge Swift Regex results to NSRange for TextKit, you convert Range<String.Index> to NSRange using the String's utf16 view. This enables accurate range mapping for NSAttributedString operations.

When should I use Swift Regex versus NSRegularExpression for text parsing?

Use Swift Regex for type-safe captures and modern pattern matching on iOS 16+, and choose NSRegularExpression when supporting older deployment targets or needing direct Foundation interoperability.

Does Swift Regex require iOS 16 for text parsing in iOS apps?

Yes, Swift Regex requires a minimum deployment target of iOS 16. For older versions, use NSRegularExpression to handle pattern matching and text parsing tasks.

What's the best way to parse dates and currencies using Swift Regex?

The best way to parse dates and currencies with Swift Regex is leveraging its type-safe captures to extract specific formats directly, then bridging the resulting Range<String.Index> to NSRange for TextKit display.

Can I use RegexBuilder for pattern matching in text views?

Yes, you can use RegexBuilder for pattern matching in text views on iOS 16+. It provides a declarative syntax for building complex patterns, with results bridged to NSRange for NSAttributedString workflows.