You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio 2017中用正则表达式给每行文本加<li>标签?

Fix: Adding
  • Tags to Each Line in Visual Studio 2017 with Regex
  • Got it, let's sort out this regex find-and-replace issue for you. The problem with your original setup is that you didn't capture the line content into a group—so $1 was empty, leading to empty <li> tags. Here's the step-by-step fix:

    • Open the Find and Replace dialog (press Ctrl+H).
    • Make sure the Use Regular Expressions toggle is enabled (it's the button with the .* icon in the dialog toolbar).
    • Set your Find what field to: ^(.*)$
      • The parentheses () wrap the entire line content into the first capture group, which we'll reference later.
      • ^ matches the start of a line, .* matches any character (except newlines) zero or more times, $ matches the end of a line.
    • Set your Replace with field to: <li>$1</li>
      • $1 pulls in the content we captured with the parentheses in the find pattern.
    • Click Replace All to apply this to every line in your file.

    Bonus: Skip Empty Lines

    If you don't want to add <li> tags to blank lines, adjust your find pattern to:
    ^(.+)$
    The + instead of * ensures we only match lines with at least one character.

    Just a quick note: Visual Studio 2017 uses its own flavor of regex, so capture groups work with standard parentheses () and you reference them with $1, $2, etc.—which you already had right, you just missed wrapping the line content in a group!

    内容的提问来源于stack exchange,提问作者Rod

    相关产品推荐
    方舟 Agent Plan

    超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

    最近更新时间:2026.05.20 08:11:38