YAML Comment Replacer

Paste YAML and give old and new text, and get back the same document with every occurrence of that text inside a comment replaced, while every key, value, and layout detail outside the comments stays exactly as written. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

Updating a piece of text scattered across many comments in a YAML config, a ticket reference, an author's initials, an outdated note, normally means hunting down every `#` by hand while being careful not to touch the actual data. This tool does that replacement for you, safely.

Because it only ever touches text after a real comment-starting `#` (never inside a quoted value), it can't accidentally corrupt a data value that happens to contain a similar-looking string.

What Is YAML Comment Replacer?

A YAML comment editor that scans the source line by line, finds each line's comment (if any) using the same quote-aware `#` detection as this category's other comment tools, and replaces every occurrence of the old text with the new text within that comment only.

Unlike the parse-and-reserialize tools in this category, this one works directly on the source text, so it preserves the document's exact original formatting outside of the edited comment text.

How YAML Comment Replacer Works

Each line is scanned character by character, tracking whether the scanner is currently inside a single- or double-quoted string; a `#` inside a string is ignored, and a `#` elsewhere only counts as a comment start when it's at the line's start or preceded by whitespace.

Once a comment's starting position is found, the substring after the `#` is searched for the old text and every occurrence is replaced, using a simple split-and-join, the same technique this site's XML Comment Replacer uses for XML comment nodes.

When To Use YAML Comment Replacer

Use it to bulk-update a repeated reference, ticket number, or note across every comment in a config file.

It's also useful for cleaning up outdated commentary (an old owner's name, a stale TODO reference) without risking a change to the underlying configuration data.

Features

Advantages

  • Never touches actual data values, only the text inside real comments.
  • Preserves the document's exact original formatting outside of the edited text, unlike tools that parse and re-serialize.
  • Correctly distinguishes a real comment `#` from one inside a quoted string, avoiding false positives.
  • Runs entirely client-side, so configuration data never leaves your browser.

Limitations

  • This is a line-by-line heuristic scan, not a full YAML parse, so it doesn't track multi-line quoted or block scalar values.
  • Replacement is a plain text substitution within each comment, not a regular expression or fuzzy match.
  • A line with no comment at all is left completely unchanged, there's no way to add a new comment with this tool.

Examples

Replacing a ticket reference across comments

Input

# see TICKET-100
retries: 3 # keep low, TICKET-100

Output

# see TICKET-200
retries: 3 # keep low, TICKET-200

Both the full-line and trailing comment's TICKET-100 reference are updated; the data line itself is untouched.

Best Practices & Notes

Best Practices

  • Run YAML Comment Extractor first to review exactly which comments exist and where the target text appears.
  • Diff the output against the original afterward to confirm only comment text changed, not the data.
  • Use an exact, distinctive search string to avoid accidentally matching an unrelated word inside a different comment.

Developer Notes

This reuses the exact `findCommentStart` quote-aware scanner from Extract Comments from YAML and Remove Comments from YAML for consistency, then applies a `String.split(from).join(to)` substitution (mirroring XML Comment Replacer's approach) only to the substring after the detected `#`, leaving everything before it on the line untouched.

YAML Comment Replacer Use Cases

  • Bulk-updating a ticket or issue reference repeated across many comments in a config
  • Cleaning up outdated authoring notes or TODOs before sharing a file
  • Standardizing comment phrasing (like a consistent "NOTE:" prefix) across a document
  • Correcting a typo that was copy-pasted into several comments

Common Mistakes

  • Expecting data values to be searched too; only text inside comments is affected.
  • Assuming this is a full YAML parse, it's a line-by-line heuristic, so multi-line string edge cases aren't handled.
  • Using a very short or common search string, which can unintentionally match unrelated comment text elsewhere in the file.

Tips

  • Run YAML Comment Extractor first to see the full list of existing comment text before deciding what to replace.
  • Use YAML Comment Remover afterward if you decide you want the comments gone entirely instead of edited.
  • Pick a distinctive, specific search string to avoid unintended matches in unrelated comments.

References

Frequently Asked Questions