liveBook · Manning

Domain-specific language

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

A domain-specific language is a language designed for expressing solutions within a particular problem domain.

A domain-specific language (DSL) is designed for expressing solutions within a particular problem domain. Regular expressions are a DSL for describing text patterns: they have their own syntax and rules, separate from Python, and appear in tools ranging from command-line utilities to databases. section 8.3.2

Replacing vowels with a regular expression

The pattern '[aeiou]' describes a character class containing lowercase vowels. Python's re.sub() applies that pattern to text and replaces each match: re.sub('[aeiou]', 'o', 'Apples and bananas!') produces 'Applos ond bononos!'. A second substitution handles uppercase vowels. section 8.3.2

>>> pattern = '[aeiou]'

Inspect the compact regex pattern used to describe the vowels. section 8.3.2

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Defines DSLs through regular expressions and demonstrates character classes and substitution, without developing broader regex syntax.
Examples
Demonstrates '[aeiou]' and re.sub() to replace lowercase and uppercase vowels in sample text.
What it assumes
Assumes basic Python text manipulation and teaches importing re before applying a regular-expression pattern.
What you can do after
Apply it via Python's re module to describe character patterns and substitute matching text.
How it connects
Connects domain-specific languages with regular expressions, Python, command-line tools, and databases.

Also explained in

Compare how 10 books explain domain-specific language →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.