Regex to replace email address domains? -


i need regex obfuscate emails in database dump file have. i'd replace domains set domain @fake.com don't risk sending out emails real people during development. emails have unique match database constraints, want replace domain , keep usernames.

i current have regex finding emails

\b[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}\b 

how convert search regex regex can use in find , replace operation in either sublime text or sed or vim?

edit:

just note, realized replace strings found @[a-z0-9.-]+\.[a-z]{2,4}\b in case, academically still interested in how treat each section of email regex token , replace username / domain independently.

sublimetext

sublimetext uses boost syntax, supports quite large subset of features in perl regex. task, don't need advanced constructs.

below 2 possible approaches:

  1. if can assume @ doesn't appear in other context (which quite fair assumption normal text), can search domain part @[a-z0-9.-]+\.[a-z]{2,4}\b , replace it.

  2. if use capturing groups (pattern) , backreference in replacement string.

    find what

    \b([a-z0-9._%-]+)@[a-z0-9.-]+\.[a-z]{2,4}\b 

    ([a-z0-9._%-]+) first (and only) capturing group in regex.

    replace with

    $1@fake.com 

    $1 refers text captured first capturing group.

note both methods above, need turn off case-sensitivity (indicated 2nd button on lower left corner), unless want remove emails written in caps.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -