> For the complete documentation index, see [llms.txt](https://regex-simplify.lacostar.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://regex-simplify.lacostar.fr/docs/web/link.md).

# link

{% hint style="warning" %}
The regex keeps the protocol optional, so some links can be false positives. \
In a future version you will be able to choose if you want to force a protocol or leave the protocol optional
{% endhint %}

{% tabs %}
{% tab title="Function types" %}

<pre class="language-typescript"><code class="lang-typescript"><strong>link(link: string): { 
</strong>    include: boolean, 
    matchs: RegExpMatchArray | null, 
    groups: Array&#x3C;{ 
        protocol: string | undefined,
        auth: string | undefined,
        username: string | undefined,
        password: string | undefined,
        alldomain: string,
        subdomain: string | undefined,
        domain: string,
        extension: string,
        ipadress: string | undefined,
        port: string | undefined,
        route: string | undefined,
        filename: string | undefined,
        query: string | undefined,
        anchor: string | undefined,
    } | null> | null
}
</code></pre>

{% endtab %}

{% tab title="Code example" %}
**Search e-mail in a string:**

```javascript
const { web } = require('regex-simplify');

const link = web.link(`
    https://discord.gg/test/image.png?query=test#anchor
    http://192.168.1.1
    http://192.168.1.1:5555
    http://username:password@domain.com
`);

console.log(link);
```

{% endtab %}

{% tab title="Function return" %}
**And here what return the function:**

```javascript
{
  include: true,
  matchs: [
    'https://discord.gg/test/image.png?query=test#anchor',
    'http://192.168.1.1',
    'http://192.168.1.1:5555',
    'http://username:password@domain.com'
  ],
  groups: [
    [Object: null prototype] {
      protocol: 'https',
      auth: undefined,
      username: undefined,
      password: undefined,
      alldomain: 'discord.gg',
      subdomain: undefined,
      domain: 'discord',
      extension: 'gg',
      ipaddress: undefined,
      port: undefined,
      route: '/test/',
      filename: 'image.png',
      query: '?query=test',
      anchor: '#anchor'
    },
    [Object: null prototype] {
      protocol: 'http',
      auth: undefined,
      username: undefined,
      password: undefined,
      alldomain: '192.168.1.1',
      subdomain: undefined,
      domain: undefined,
      extension: undefined,
      ipaddress: '192.168.1.1',
      port: undefined,
      route: undefined,
      filename: undefined,
      query: undefined,
      anchor: undefined
    },
    [Object: null prototype] {
      protocol: 'http',
      auth: undefined,
      username: undefined,
      password: undefined,
      alldomain: '192.168.1.1',
      subdomain: undefined,
      domain: undefined,
      extension: undefined,
      ipaddress: '192.168.1.1',
      port: '5555',
      route: undefined,
      filename: undefined,
      query: undefined,
      anchor: undefined
    },
    [Object: null prototype] {
      protocol: 'http',
      auth: 'username:password',
      username: 'username',
      password: 'password',
      alldomain: 'domain.com',
      subdomain: undefined,
      domain: 'domain',
      extension: 'com',
      ipaddress: undefined,
      port: undefined,
      route: undefined,
      filename: undefined,
      query: undefined,
      anchor: undefined
    }
  ]
}
```

{% endtab %}
{% endtabs %}
