Replace everything before certain key

  • Hi there,
    is there any symbol or command that will get everything before a certain key value in Find functionality?

    For example: Anything before “id” I want to get deleted.

        Line 90:     "id": 1111111
        Line 99:     "id": 2222222

    And I want to get this
    “id”: 1111111
    “id”: 2222222

    Thank you

    • Find What: (?-s)^.*(?="id")
    • Replace With: (empty)
    • Search Mode: Regular Expression

    This will search from the beginning of the line, until it finds "id" (in normal double-quotes), and replace it with nothing (ie, delete it). The (?-s) makes sure that the match-anything .* character won’t match newlines, so each match is limited to a single line. (This could also be accomplished by unchecking . matches newline in the dialog box… but by putting it into the regex, the expression will work even if someone didn’t notice the checkbox.)

    FYI: if you have further regex needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backword to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post, where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.

  • I knew there was some command users use but couldn’t find what kind of. I did some replacing by myself but hit the wall everytime i had to replace Line xxxx and couldn’t think of how to reference before the “id”. Anyway thank you very much for helping me and tips for my next post.

Log in to reply