Question: I have a URL `(https://example.com/myfile.txt)` of a file and I want to upload it to my bucket `(gs://my-sample-bucket)` on Google Cloud Storage. 

What I am currently doing is: 

1. Downloading the file to my system using the requests library.
2. Uploading that file to my bucket using python function.

Is there any way I can upload the file directly using the URL.

Answer: 
We could try using negative lookaheads:

```
^(?:(?!.*\.)(?!\d{13})|(?=.*\.)(?![0-9.]{14}))\d+(?:\.\d{1,6})?$

```

[Demo
----](https://regex101.com/r/GEMn0m/1)

Here is an explanation of the regex:

```
^(?:                        from the start of the string
    (?!.*\.)(?!\d{13})      assert that no more than 12 digits appear
                            (in the case of a number with NO decimal point)
    |                       or
    (?=.*\.)(?![0-9.]{14})) assert that no more than 13 digits/decimal point appears
                            (in the case of a number which HAS a decimal point)
    \d+                     then match one or more digits (whole number portion)
    (?:\.\d{1,6})?          followed by an optional decimal component (1 to 6 digits)
$                           end of the string

```
**TL;DR;**

```
^(?!(?:\D*\d){13})\d*[.]?\d{0,6}$ 
^(?=(?:\D*\d){0,12}\D*$)\d*[.]?\d{0,6}$

```

You can use a simple positive lookahead approach: keep your pattern (if it works as you expect) and insert

```
(?=(?:\D*\d){0,x}\D*$)

```

right after `^` and change the `x` to the required amount of digits.

So, you may use

```
^(?=(?:\D*\d){0,12}\D*$)\d*[.]?\d{0,6}$
 ^^^^^^^^^^^^^^^^^^^^^^^

```

The `(?=(?:\D*\d){0,12}\D*$)` matches a location that is immediately followed with zero to 12 occurrences of any 0+ non-digit chars followed with one digit one and then having any 0+ non-digits to the end of the string.

**See the [regex demo](https://regex101.com/r/k4lpJK/1)**

Alternatively, disallow a string with more than 13 digits:

```
^(?!(?:\D*\d){13})\d*[.]?\d{0,6}$
 ^^^^^^^^^^^^^^^^^

```

The `(?!(?:\D*\d){13})` is a negative lookahead that fails the match if there are 13 occurrences of any 0+ non-digits followed with a single digit chars.

This is better than the positive lookahead approach when you need to allow an empty string.

**See the [regex demo](https://regex101.com/r/k4lpJK/2)**