All Projects → katursis → Pawn.Regex

katursis / Pawn.Regex

Licence: MIT License
🔎 Plugin that adds support for regular expressions in Pawn

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to Pawn.Regex

samp-ptl
SA:MP Plugin Template Library (C++17)
Stars: ✭ 16 (-52.94%)
Mutual labels:  sa-mp, samp
PacPaw
Pawn package manager for SA-MP
Stars: ✭ 14 (-58.82%)
Mutual labels:  sa-mp, samp
tokenquery
TokenQuery (regular expressions over tokens)
Stars: ✭ 28 (-17.65%)
Mutual labels:  regex, regular-expressions
simplematch
Minimal, super readable string pattern matching for python.
Stars: ✭ 147 (+332.35%)
Mutual labels:  regex, regular-expressions
rustext
Fix Russian text plugin for SA-MP: GameText's, TextDraw's and Menu's
Stars: ✭ 15 (-55.88%)
Mutual labels:  sa-mp, samp
code-parse.inc
Pre-processor macros for analysing PAWN functions.
Stars: ✭ 23 (-32.35%)
Mutual labels:  sa-mp, samp
python-hyperscan
A CPython extension for the Hyperscan regular expression matching library.
Stars: ✭ 112 (+229.41%)
Mutual labels:  regex, regular-expressions
eSelection
Dynamic model selection library for SA-MP servers
Stars: ✭ 28 (-17.65%)
Mutual labels:  sa-mp, samp
unmatcher
Regular expressions reverser for Python
Stars: ✭ 26 (-23.53%)
Mutual labels:  regex, regular-expressions
protection
Flexible server protection system (development)
Stars: ✭ 23 (-32.35%)
Mutual labels:  sa-mp, samp
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (+73.53%)
Mutual labels:  regex, regular-expressions
RgxGen
Regex: generate matching and non matching strings based on regex pattern.
Stars: ✭ 45 (+32.35%)
Mutual labels:  regex, regular-expressions
samp-discord-plugin
SA:MP Discord Rich Presence plugin
Stars: ✭ 63 (+85.29%)
Mutual labels:  sa-mp, samp
expressive-ts
A functional programming library designed to simplify building complex regular expressions
Stars: ✭ 78 (+129.41%)
Mutual labels:  regex, regular-expressions
GWRP-0.3
Игровой режим для San Andreas Multiplayer
Stars: ✭ 22 (-35.29%)
Mutual labels:  sa-mp, samp
samp-node-lib
NodeJS library for Scripting San Andreas Multiplayer:SAMP depends on samp-node plugin
Stars: ✭ 23 (-32.35%)
Mutual labels:  sa-mp, samp
Ruby Regexp
Learn Ruby Regexp step by step from beginner to advanced levels with plenty of examples and exercises
Stars: ✭ 79 (+132.35%)
Mutual labels:  regex, regular-expressions
samp-foreach
foreach standalone include (non y_iterate version)
Stars: ✭ 20 (-41.18%)
Mutual labels:  sa-mp, samp
Open-GTO
RPG gamemode for SA-MP
Stars: ✭ 45 (+32.35%)
Mutual labels:  sa-mp, samp
lc-data-intro
Library Carpentry: Introduction to Working with Data (Regular Expressions)
Stars: ✭ 16 (-52.94%)
Mutual labels:  regex, regular-expressions

Pawn.Regex

🔎 Plugin that adds support for regular expressions in Pawn

Why is it better than others plugins? Because it gives you an opportunity to get match groups.

Natives

native Regex:Regex_New(const pattern[], E_REGEX_FLAG:flags = REGEX_DEFAULT, E_REGEX_GRAMMAR:grammar = REGEX_ECMASCRIPT);
native Regex_Delete(&Regex:r);

native Regex_Check(const str[], Regex:r, E_MATCH_FLAG:flags = MATCH_DEFAULT);
native Regex_Match(const str[], Regex:r, &RegexMatch:m, E_MATCH_FLAG:flags = MATCH_DEFAULT);
native Regex_Search(const str[], Regex:r, &RegexMatch:m, &pos, startpos = 0, E_MATCH_FLAG:flags = MATCH_DEFAULT);
native Regex_Replace(const str[], Regex:r, const fmt[], dest[], E_MATCH_FLAG:flags = MATCH_DEFAULT, size = sizeof dest);

native Match_GetGroup(RegexMatch:m, index, dest[], &length, size = sizeof dest);
native Match_Free(&RegexMatch:m);

Examples

#include <Pawn.Regex>

stock IsRpNickname(const nickname[])
{
  static Regex:regex;
  if (!regex) regex = Regex_New("[A-Z][a-z]+_[A-Z][a-z]+");

  return Regex_Check(nickname, regex);
}

stock IsValidEmail(const email[])
{
  static Regex:regex;
  if (!regex) regex = Regex_New("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");

  return Regex_Check(email, regex);
}

public OnPlayerCommandText(playerid, cmdtext[])
{
  static Regex:regex;
  if (!regex) regex = Regex_New("^\\/([\\w]+)\\s*(.+?)?\\s*$");

  new RegexMatch:match;
  if (!Regex_Match(cmdtext, regex, match)) return 0;

  new cmd[16], cmd_length;
  Match_GetGroup(match, 1, cmd, cmd_length);

  new params[256], params_length;
  Match_GetGroup(match, 2, params, params_length);

  printf("cmd '%s' (len %d), params '%s' (len %d)", cmd, cmd_length, params, params_length);

  Match_Free(match);

  return 1;
}

stock SplitAndPrint(const str[])
{
  static Regex:regex;
  if (!regex) regex = Regex_New("[^\\s]+");

  new RegexMatch:match, pos, startpos;
  while (Regex_Search(str, regex, match, pos, startpos))
  {
    new word[128], length;
    Match_GetGroup(match, 0, word, length);

    printf("word: %s, len: %d", word, length);

    startpos += pos + length;

    Match_Free(match);
  }
}

stock ReplaceString(const str[], const regexp[], const fmt[], dest[], size = sizeof dest)
{
  new Regex:regex = Regex_New(regexp);
  if (!regex) return;

  Regex_Replace(str, regex, fmt, dest, MATCH_DEFAULT, size);

  Regex_Delete(regex);
}

main()
{
  new str[256];

  ReplaceString("Regex.Pawn", "(.+)\\.(.+)", "$1.$2 => $2.$1", str);

  printf("%s", str);

  SplitAndPrint("4 8 15 16 23 42");

  OnPlayerCommandText(-1, "/ban 42");
  OnPlayerCommandText(-1, "/kill");

  printf("%d %d %d %d", IsRpNickname("Firstname_Lastname"), IsRpNickname("katursis"), IsValidEmail("[email protected]"), IsValidEmail("email.example.com"));
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].