使用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
- Open the Find/Replace dialog: Use the shortcut
Cmd+F, or go to Edit > Find > Find... in the menu bar. - Enable regex mode: Check the Regular Expression box at the bottom of the dialog (this is critical—don't skip it!).
- Enter the pattern to find:
(?<!^)(\s+)(\d+\.) - Enter the replacement text:
\n$2 - 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
相关产品推荐
相关产品推荐

