multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.4k stars 435 forks source link

Improvments regarding regex #3087

Open CrosRoad95 opened 1 year ago

CrosRoad95 commented 1 year ago

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

  1. "pregMatch", what preg mean? under the hood it is just regex, replace "preg" with "regex" what will be more understatemenable for people
  2. pregFind, pregMatch, pregReplace are accepting regex as string what is not good from performance perspective

Describe the solution you'd like

  1. rename pregFind, pregMatch, pregReplace to regexFind, regexMatch, regexReplace
  2. add function to create compiled regex, pcre library used in mta allow it https://chat.openai.com/share/63d127d9-3abd-418e-8580-e90825bff8bd

local regex = createRegex(...) regexMatch(regex, ...)

can be beneficial in hot paths

Or do it a bit different, make regex functions compile in background regex, if you do pregMatch(x) for the first time, regex gets compiled and stored in cache, then if you use this function again with same regex it will reuse previously compiled regex. Remember to add some functionality that will cache up to 1000 regexes, maybe it should be configurable from server config

Describe alternatives you've considered

/

Additional context

are there any other functions we can add apart of find, match and replace?

Security Policy

Kenix157 commented 1 year ago

It's not regex, it's PCRE expressions

naming is very simmular like PHP for example: https://www.php.net/manual/ru/function.preg-match.php

and etc..

We don't have regex expressions like in Javascript, i think we should add new functions instead of replace current names.