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: 
You could use a positive lookahead to check for either a number with a decimal place with up to 6 digits after it or a string of 12 digits) and then match up to 13 characters in total:

```
^(?=\d*\.\d{0,6}$|\d{1,12}$).{1,13}$

```

For this input, the 2nd and 5th values will match:

```
1234567890123
123456.789012
12345.6789012
1234567.890123
12345.67890

```

[Demo on regex101](https://regex101.com/r/vHdArC/3)
**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)**