Understanding TRegExpr lazarus / 21-General ---------------------------------------------------------------------- pmesquita · 2022-08-28 17:17 Guys,. Anyone know TRegex (https://github.com/andgineer/TRegExpr)? I'm playing with TRegExpr and according to the website: https://regex101.com/ if I use the expression: ^[a-z]([\\.](?![\\.])|[a-z]){5,50}[a-z]$ to validate the text: foo.bar. The site is valid, but if you throw this same expression to the FPC it "screams" that the position is unknown... Note: the two backslashes are because the "schema" field is made a "GetJSON" in the content.. Validation code: Function CheckPattern(AValue, APattern: String): Boolean; var    LRegex: TRegExpr;   Begin    LRegex:= TRegExpr.Create;    try     LRegex.Expression:= APattern;     LRegex.ModifierI:= False;     LRegex.ModifierS:= True;     LRegex.ModifierX:= True;     Result:= LRegex.Exec(AValue);    finally     FreeAndNil(LRegex);    End;   End; ---------------------------------------------------------------------- AlexTP · 2022-08-28 17:19 I am the maintainer. FPC cannot find this part: (?![\\.]) It is called 'assertion' and it was added to FPC 'trunk' but was not added YET to the last FPC release. And, 'assertion' must be at the very end of expression. ---------------------------------------------------------------------- pmesquita · 2022-08-28 18:51 I'm talking to the right person.. understood, but I'm using the master version in Git. So the expression should look like this: ^[a-z][\\.][a-z]{5.50}(?![\\.])$ ? ---------------------------------------------------------------------- AlexTP · 2022-08-28 18:55 That is also 'not at the very end', notice the $ at the very end. BTW, you can test this in CudaText (with latest TRegExpr). Editor shows detailed regex errors. ---------------------------------------------------------------------- pmesquita · 2022-08-28 22:19 what's up.. I think I understand, so the 'assertions' should always be declared or at the beginning or end of the expression would it be a current limitation or implementation? Because in my understanding and using CudaText I arrived at the expression: ^[a-z]+[\.][a-z]{1,50}$(?![\.]) where it works for what I need, however I a question arose: Would the assertion (?![\.]) at the end of the text (after the $) be a regular expression for the "[\.]" declared earlier in order to avoid repetition of the dot (.) ? ---------------------------------------------------------------------- AlexTP · 2022-08-29 08:20 Yes, it is the limitation, https://regex.sorokin.engineer/en/latest/re gular_expressions.html#assertions - docs tell it. QuoteWould the assertion (?![\.]) at the end of the text (after the $) be a regular expression for the "[\.]" declared earlier in order to avoid repetition of the dot (.) ?I did not understand. En is not my native lang. ---------------------------------------------------------------------- Martin_fr · 2022-08-29 10:16 In this case the regex may be "fixable" The orig regex matches any text that - starts and ends in a letter - is between 7 and 52 chars long - can have any amount of single dots between any 2 letters. Since the text has only dots and letters, the lookahead (?!\\.)  means a letter must follow => and hence this is a word boundary. I did not test, but I would expect that this should work: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ^[a-z](\\.\\b|[a-z]){5,50}[a-z]$ Depending on what "only at the end of an expression" means exactly... (I.e. only at the very end of the entire regex, or any sub- expression?), there may be another options. The condition is that the overall length should be between 7 and 52 chars.... If we temporary ignore the length, the regex becomes real simple:  Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ^[a-z]+(\\.[a-z]+)*$- starts with one or more letters - followed by zero, one or more: dot with at least one letter after it   (that also ensures the last char is a letter) If we can place the lookahead at the very start, we can check the length first Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ^(?=.{7,52}$)[a-z]+(\\.[a-z]+)+$That does 2 matches, both from the start, and both required to succeed. - check the length - check the content as explained