Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!