WorldGuard icon indicating copy to clipboard operation
WorldGuard copied to clipboard

Valid ID pattern for protected regions can be simplified

Open elgbar opened this issue 4 years ago • 0 comments

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,}$.

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

And explanation from regex101 using the java 8 favour.

Old

old

New

new

elgbar avatar May 24 '21 13:05 elgbar