Skip to content

Instantly share code, notes, and snippets.

@mogarick
Last active July 18, 2021 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogarick/f5ca97fc527343e631935c2fefb31bef to your computer and use it in GitHub Desktop.
Save mogarick/f5ca97fc527343e631935c2fefb31bef to your computer and use it in GitHub Desktop.
Search and replace de mongoID JSON object para serializar a solo string

Un mongoID en json tiene la forma siguiente:

{
  _id: {
     $oid: "58ae6b11fd54e89021a96610",
   }
}

Una versión limpia, con el puro string sería:

{
_id: "58ae6b11fd54e89021a96610"
}

Para lograrlo, se divide la regexp en 3 grupos de captura, para que se indique que solo que mantiene lo que esta con comillas, que sería el grupo 2 ($2) Search expression: (\{\s*\$oid:\s*)("[0-9a-f]*")(,[\s\n]*\}) Replace expression: $2

OJO: \n es necesario en vscode para hacer que haga búsqueda multiline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment