Remove Lines Containing a Word
Remove lines containing a word or regex pattern from text online. Match case or whole words, or invert to keep only matching lines. Free and private.
How to use Remove Lines Containing
- 1Paste your lines of text.
- 2Type the word or pattern, and set case, whole-word, regex or invert options.
- 3Copy the remaining lines; the summary shows how many lines were removed.
What makes it better
- Plain text or regular-expression matching
- Case-sensitive and whole-word options
- Invert to keep only matching lines
- Invalid patterns show a message instead of failing
About Remove Lines Containing
Remove Lines Containing deletes every line that includes the word, phrase or regular expression you enter. Switch on “Invert” to do the opposite and keep only the lines that match, which makes it handy for filtering logs, lists and exported data. The summary reports how many lines were removed.
Common uses
- Filter ERROR or DEBUG lines out of a log excerpt.
- Drop every line mentioning a competitor, name or test value.
- Keep only the lines that contain a keyword with Invert.
- Remove comment lines from a config using a pattern like ^#.
Example
Input
INFO Server started ERROR Disk full INFO Request handled error: timeout WARN Slow response
Result
INFO Server started INFO Request handled WARN Slow response
Good to know
- Matching is not case-sensitive unless you turn that option on. Outside regex mode the text is matched literally, so a dot matches only a dot.
- Whole word matching treats letters, digits and underscores as word characters.
- With an empty pattern nothing is removed. Regex uses the browser’s JavaScript syntax.
Remove Lines Containing FAQ
How do I delete all lines that contain a certain word?
Type the word in the pattern box. Every line containing it is removed. The example above removes lines containing “error”, whatever their capitalisation.
How can I keep only the lines that contain a word?
Turn on “Invert”. The tool then keeps only the matching lines and removes everything else.
Can I use a regular expression?
Yes. Turn on “Regular expression” and enter a JavaScript pattern, for example ^# to remove comment lines or \d{4} for lines with four digits in a row.
What does “Whole word” do?
It only matches the pattern when it is not part of a longer word, so “cat” matches “the cat sat” but not “catalog”.
What happens with an invalid regular expression?
You see an error message and your text is left unchanged until the pattern is valid.