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

使用Regular Expressions在TextWrangler中拆分合并记录行

Fix Merged Records in TextWrangler with Regular Expressions

Got it, let's tackle this record-splitting problem in TextWrangler with regex—super straightforward once you nail the pattern. Here's exactly what you need to do:

Step-by-Step Replacement Process

  1. Open the Find/Replace dialog: Use the shortcut Cmd+F, or go to Edit > Find > Find... in the menu bar.
  2. Enable regex mode: Check the Regular Expression box at the bottom of the dialog (this is critical—don't skip it!).
  3. Enter the pattern to find:
    (?<!^)(\s+)(\d+\.)
    
  4. Enter the replacement text:
    \n$2
    
  5. Verify first (optional but smart): Click Find Next a few times to confirm it's only targeting the start of merged records (not the first record in a line). If it looks right, hit Replace All to split all merged lines at once.

What This Regex Does (Breakdown)

Let's unpack the pattern so you understand why it works:

  • (?<!^): A negative lookbehind that ensures we're not at the start of a line. This prevents us from messing up your properly formatted first records.
  • (\s+): Captures one or more whitespace characters (the space between the end of one record and the start of the next merged one).
  • (\d+\.): Captures one or more digits followed by a dot—this is the start of a new record's numbering (e.g., 2., 5.).

In the replacement, \n$2 swaps the captured whitespace for a newline, then puts the record numbering ($2 refers to the second captured group) right after the newline—perfectly matching your desired "record number. Last, First" format.

Quick Notes

  • Backup first: Always save a copy of your original file before running bulk replacements—just in case you need to roll back.
  • Adjust for edge cases: If merged records are separated by something other than spaces (like tabs or odd characters), tweak \s+ to match that. For tabs, use \t+; for any non-word character, use \W+ (test this first to avoid accidental replacements).
  • Handle extra-long lines: This regex works for 2, 5, or even more merged records in a single line—it'll hit every non-start-of-line record number and split it into a new line.

内容的提问来源于stack exchange,提问作者mysql_python-connect_user

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:57:59