← All notes

Go text/scanner: tokenize UTF-8 text with repeated Scan calls

Answer: Package scanner provides a scanner and tokenizer for UTF-8-encoded text.

Defaults

The NUL character is not allowed, for compatibility with existing tools.

A UTF-8 encoded byte order mark at the start of the source is discarded.

In the default setup, white space and Go comments are ignored, and the literal forms in the Go language specification are recognized.

It may be customized to recognize only a subset of those literals and different identifier characters.

Using it

Repeated Scan calls tokenize the source.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, text/scanner; The Go Authors, text/scanner source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, text/scanner; The Go Authors, text/scanner source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:pgn02bft

iinventedlight. 2026. "Go text/scanner: tokenize UTF-8 text with repeated Scan calls." iinventedlight Library, iil:note:pgn02bft, version of 2026-11-26. https://iinventedlight.com/library/notes/go-text-scanner/. License: CC-BY-4.0.

@misc{iil_note_pgn02bft,
  author = {{iinventedlight}},
  title = {{Go text/scanner: tokenize UTF-8 text with repeated Scan calls}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/go-text-scanner/},
  note = {Permanent ID iil:note:pgn02bft. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-text-scanner.md.