LLI Wiki — My Digital Knowledge Base

VS Code: clean text with regular expressions

Regular expressions for VS Code Find and Replace to remove non-ASCII characters, empty lines and duplicate lines.

VS Code's Find and Replace accepts regular expressions. Press Ctrl+F, toggle Replace mode, and enable Use Regular Expression (the .* icon). Then run the patterns below with Replace All.

Remove non-ASCII characters

Find:

[^\x00-\x7f]

Replace with an empty string.

Remove empty lines

Find:

^(?:[\t ]*(?:\r?\n|\r))+

Remove duplicate consecutive lines

Find:

^(.*)(\n\1)+$

Replace with:

$1

An alternative pattern from the same source:

search: ((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s]*?)^\2$(?:\n)?

replace with: $1

Change the case of a selection

The Stack Overflow question on converting a selected block to upper case is listed under References.

References

Mastodon LLIMastodon SocialFosstodon