Question: I'm trying to create a regex to find a string with a double-underscore `__`, multiple underscores `_` and then another double-underscore `__` and extract the part before the final `__<string>`  

The first delimiter should be `__` and then multiple `_`, and string ends with `__<String>`

The result should be such that string before the second \_\_

example 1- `UK__SATHISH_KUMAR__LONDON` should result to `UK__SATHISH_KUMAR`

example 2- `UK__SATHISH_KUMAR_MALE__LONDON` should result to `UK__SATHISH_KUMAR_MALE`

```
public static final String RULE_FILE_NAME_PATTERN =
    "(([a-zA-Z]+)__(([a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+_[a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+_[a-zA-Z]+)|([a-zA-Z]+)))(__[\\w]+)*";

```

This pattern works but fails sonarqube as it's long, can some one help to get a shorter regex?

Answer: 
Pagination limit of `10k` means

* For the applied `query` only the first 10k results can be displayed.
* `from:0 size:10,001` will given an error "Result window is too large"
* `from:10000, size:10` will given an error "Result window is too large"
* In the above 2 cases we are trying to access 10000+ offset of the document of the current query, hence the exception

---

* `from` doesn't represent `pageNumber`, instead it represents `starting offset`
The limit is called [max\_result\_window](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-max-result-window) and default value is 10k. Mathematically this is the max value `size+from` can take.

from:1, size:10000 will give error.

from:5, size:9996 will give error.

from:9999, size:2 will give error.

[Search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after) is the recommended alternative if you want deeper results.