Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Remove port and keep the host

I've URL like following

https://www.aaaa.com:5000  -> https://www.aaaa.com
https://bbbb.com:443   -> https://bbbb.com
https://cccc.com     -> https://cccc.com

I need to remove only the port ..

I've tried with the following which doesn't works, it takes all the data

https://regex101.com/r/CIiALR/1

(https?://.*):(\d*)\/?(.*)`

The trick is that I must use only regex not js lib, as I need it for using Vector.

https://vector.dev/docs/reference/vrl/

Also: https://vector.dev/docs/reference/vrl/#parse-custom-logs

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

No need for regex, you may use the url object for this kind of work.

var url = new URL('https://www.aaaa.com:5000');
url.port = '';
console.log(url.toString());

More about the url object - https://developer.mozilla.org/en-US/docs/Web/API/URL

about 4 years ago · Juan Pablo Isaza Denunciar

0

Looking at https://vector.dev/docs/reference/vrl/ you can use a named capture group and optionally match the port number:

^(?P<withoutport>https?://[^/\s]+?)(?::\d+|$)
  • ^ Start of string
  • (?P<withoutport> Named group
    • https?:// Match the protocol
    • [^/\s]+? Match by any char except / or a whitespace char in a non greedy way
  • ) Close named group
  • (?::\d+|$) Match : and 1+ digits, or assert the end of the string

Regex demo

Or you can make it as specific as you require:

 ^(?P<withoutport>https?://[^/\s]+?)(?:[:?#/]\S*)?$

Regex demo

about 4 years ago · Juan Pablo Isaza Denunciar

0

Depending on the version of vector you are using - I would suggest using the built in parse_url function to extract out which parts you want.

Example TOML:

[sources.my_demo_logs_source]
type = "demo_logs"
format = "shuffle"
lines = [ "https://www.aaaa.com:5000" , "https://bbbb.com:443", "https://cccc.com" ]

[transforms.my_transform]
type = "remap"
inputs = [ "my_demo_logs_source" ]
source = """
url_parts = parse_url!(.message)
.url = join!([ url_parts.scheme, url_parts.host ],  "://")
"""

[sinks.my_sink_id]
type = "console"
inputs = [ "my_transform" ]
target = "stdout"

  [sinks.my_sink_id.encoding]
  codec = "json"

Example output:

{"message":"https://bbbb.com:443","source_type":"demo_logs","timestamp":"2022-06-28T07:20:45.202665432Z","url":"https://bbbb.com"}
{"message":"https://www.aaaa.com:5000","source_type":"demo_logs","timestamp":"2022-06-28T07:20:46.202754200Z","url":"https://www.aaaa.com"}
{"message":"https://cccc.com","source_type":"demo_logs","timestamp":"2022-06-28T07:20:47.201350600Z","url":"https://cccc.com"}

This was tested with:

❯ vector --version
vector 0.22.0 (x86_64-unknown-linux-gnu 5e937e3 2022-06-01)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda