Project started: 15/11/2019, Last updated: 15/11/2019
This is a C++ module for Garry's Mod which gives developers access to the Regular Expressions string matching standard. I wanted to make this because Lua Patterns are limited in functionality and useless to learn if you've already learned Regex (also when there's already a standard in place they should never have been created in the first place)
- Download the latest release binary file for your operating system (
win32
for Windows,osx
for MacOS andlinux
for Linux) - Rename the DLL prefix to match the realm you'll be using it on. (e.g. rename it to
gmsv_regex_win32.dll
if you're using it serverside on Windows, orgmcl_regex_win32.dll
if you're using it clientside on Windows, etc.) - Navigate to your server's root directory (where srcds.exe, garrysmod, bin, etc. are)
- Create a new folder inside
garrysmod/lua/
calledbin
if it doesn't already exist. - Place the renamed module (dll) into that folder.
- Use the module in any Lua script by calling
require("regex")
.
Here is a basic example on how to use this module:
require("regex")
local message = "viral32111<76561198168833275,STEAM_0:1:104283773> said \"Hello World!\""
local regularExpression="^(.+)<(\\d{17}),(STEAM_\\d:\\d:\\d+)> said \"(.*)\"$"
local matches = regex.match(message,regularExpression)
PrintTable(matches)
The output of this would be:
0 = viral32111<76561198168833275,STEAM_0:1:104283773> said "Hello World!"
1 = viral32111
2 = 76561198168833275
3 = STEAM_0:1:104283773
4 = Hello World!
(For more examples, check the examples folder)
Run build.bat
to generate a Visual Studio 2019 for Windows using the supplied premake5 configuration. This will create a new folder called project
which will contain the Visual Studio project/solution files.
Once you've made your changes to the source code, press CTRL+B (or Build > Build gm_steam). This will generate the .dll file inside a build
folder.