Skip to content

Instantly share code, notes, and snippets.

@akingdom
Last active May 16, 2025 09:57
Show Gist options
  • Save akingdom/6df318e009dbbf2a3833f29750267c9b to your computer and use it in GitHub Desktop.
Save akingdom/6df318e009dbbf2a3833f29750267c9b to your computer and use it in GitHub Desktop.

BBEdit Grep Patterns

Author: Andrew Kingdom Note: These are grep patterns I find useful for the BBEdit text editor on MacOS. Some templates may need modification/changes before use on your specific data.

  • Remove Blank Lines

    • Find: ^\s*$\n
    • Replace: (empty string)
  • Pascal Comment to C Comment

    • Find: {([^}]*)}
    • Replace: /* \1 */
  • C++ Comment to C Comment

    • Find: //(.*)
    • Replace: /* \1 */
  • Run of Spaces to One Tab

    • Find: +
    • Replace: \t
  • C Function Header

    • Find: ^[^ \t#\n/@][^\n]*\([^\n]*\)$
    • Replace: (empty string)
  • C Comment to Pascal Comment

    • Find: /\*([^\n]*)\*/
    • Replace: { \1 }
  • Shift Variables Right

    • Find: (.*)(\t\t*)(.*)
    • Replace: \1\2\t\3
  • Shift Variables Left

    • Find: (.*)(\t)(\t*)(.*)
    • Replace: \1\3\4
  • Lower Case SRC values in IMG tags

    • Find: (<img [^>]*src\s*=\s*")([^"]+)("[^>]*>)
    • Replace: \1\L\2\E\3
  • Lower Case HREF values in A tags

    • Find: (<a [^>]*href\s*=\s*")([^"]+)("[^>]*>)
    • Replace: \1\L\2\E\3
  • Column #2

    • Find: ^[^\t]+\t([^\t]+)
    • Replace: \1
  • Dotted Quad

    • Find: (\d+\.){3}\d+
    • Replace: foo bar
  • Xcode Logs: Strip Prefix — requires the newlines versus \n

    • Find: `2022-02-15 13:\d\d:\d\d.\d\d\d\d\d\d+1100 [A-Za-z]*

[\d*:\d*] `

  • Replace: (empty string)

  • Xcode Logs: Strip Context

    • Find: Context@0x[0-9A-F]*: ............ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d.\d\d\d
    • Replace: (empty string)
  • BBEdit Find: Remove Path

    • Find: .*:\d*:\s(.*)
    • Replace: \1
  • Xcode Find: Remove Time and Process — requires the newlines versus \n

    • Find: `.*]

\s*(.*)`

  • Replace: \1

  • List to Objective-C Dictionary

    • Find: (.*)\r
    • Replace: @"\1" : \1,\r
  • Replace 2 or More Spaces with Tab

    • Find: \s\s\s*
    • Replace: \t
  • JavaScript Object Function to Plain Function

    • Find: (\s*)([a-zA-Z_]*):\sfunction\s*(\(.*\))(\s*)
    • Replace: \1function \2 \3\4
  • Split Delimited Text into Two Columns

    • Find: ([^\|]*)\|([^\|]*)\|
    • Replace: \1\t\2\r
  • Extract "prompt": "..."

    • Find: "prompt":"(.*?(?:\\.|[^"])*)"
    • Replace: \1\r—\r
  • Find Mid-Prompt Monsters

    • Find: ^.* monster .*$\r—\r
    • Replace: (empty string)
  • Remove // Comments

    • Find: //.*$
    • Replace: (empty string)
  • Remove Blank Line Whitespace

    • Find: \r[\s\t]*$
    • Replace: (empty string)
  • Extract <img> Elements

    • Find: &lt;img id="([^"]*)" .*src="([^"]*)" .*alt="([^"]*)".*&gt;
    • Replace: {"title":"\1","path":"\2","description":"\3"},
  • 2× Leading Spaces → Tabs (Repeat Until None Found)

    • Find: ^(\t*)( {2})
    • Replace: \1\t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment