EngineHub / EngineHub/WorldGuard

Valid ID pattern for protected regions can be simplified

Open
#1,772 0 comments 0 reactions 0 assignees View on GitHub
status:pending type:feature-request
Dominant language
Java
Stars
938
Forks
671
PR merge metrics
No merged PRs in 30d

Description

## Is your feature request related to a problem? Please describe.

Looking into the patterns of region I noticed the regex can be simplified. As of the latest commit `VALID_ID_PATTERN` looks like this [`^[A-Za-z0-9_,'\\-\\+/]{1,}$`](https://github.com/EngineHub/WorldGuard/blob/149d1f84e84fcf7c3af4e201f4408401b5de97f2/worldguard-core/src/main/java/com/sk89q/worldguard/protection/regions/ProtectedRegion.java#L57).

## Describe the solution you'd like

The pattern can be simplified to `^[A-Za-z0-9_,'\-+/]+$`. This new pattern does of course express the exact same thing.

There are two changes
* The end has been changed from `{1,}` to `+`.
* Using a `+` this is a more common way of writing the same thing, improving readability.
* There is no need to escape a `+` in a square bracket.
* This again improves readability, by only escaping where needed.

## Describe alternatives you've considered

The alternative is to leave it, however it does slightly degrade the quality of code as stated above.

## Additional context

Both patterns as a rail diagram
* [Old](https://regexper.com/#%5E%5BA-Za-z0-9_%2C'%5C-%5C%2B%2F%5D%7B1%2C%7D%24)
![Old](https://user-images.githubusercontent.com/1556738/119358251-bc067700-bca8-11eb-872e-908e727d8f6e.png)
* [New](https://regexper.com/#%5E%5BA-Za-z0-9_%2C'%5C-%2B%2F%5D%2B%24)
![Old](https://user-images.githubusercontent.com/1556738/119358144-a2652f80-bca8-11eb-9039-ad02b9d204af.png)

And explanation from [regex101](https://regex101.com/) using the java 8 favour.

Old

![old](https://user-images.githubusercontent.com/1556738/119357117-7b5a2e00-bca7-11eb-843e-6d5086eb4e4b.png)

New

![new](https://user-images.githubusercontent.com/1556738/119357259-a6448200-bca7-11eb-88b5-eb144f56519d.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.