excess whitespace after regex "line end" character breaks patterns invisibly
activate alias with excess whitespace, but show hint above "did you really want to do that?"
same goes for triggers, etc. all places with regex and not only alias like this example.
excess space can sometimes happen unintentionally when copy/pasting..
example alias:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<AliasPackage>
<Alias isActive="yes" isFolder="no">
<name>Wavecall Distance</name>
<script>send("invoke wavecall " .. matches[2] .. " " .. matches[3])
--I want to type wcn5 and have it send "invoke wavecall n 5"</script>
<command></command>
<packageName></packageName>
<regex>^wc(\w+)(\d+)$ </regex>
</Alias>
</AliasPackage>
</MudletPackage>
Can't be recognized in screenshot:

Workaround: click at the end of pattern line and "mark all" (Ctrl+A):

You could then see there is too much white space, should be like this instead:

Or just have people copy/paste their alias in chat for comparison
Though very unlikely it is not impossible for a regex to end with \$ so just looking for trailing spaces after a $ is not 100% foolproof.
:bulb: It would be nice if we could apply QTextOption::ShowTabsAndSpaces but as the dlgTriggerPatternEdit::lineEdit_pattern element is a QLineEdit it does not have the capability to have that option...
馃挕 It would be nice if we could apply
QTextOption::ShowTabsAndSpaces
Doesn't sound quite nice to me..
Though _very_ unlikely it is not _impossible_ for a regex to end with
\$so just looking for trailing spaces after a$is not 100% foolproof.
Hence we don't block that usage but only inform: Did you really?
So that could lead to the first use of the (void) dlgTriggerEditor::showWarning(const QString& error) method... :grinning:
What if the regex needs to end in a space - Mudlet quietly whittling spaces off - and not providing a work-around would be even worse.
Mudlet says: NO! you can not have whitespace at the beginning or end of your "regexp" triggers.
You very much still can, via \s+ or \s{,4} and similar others... Many ways to skin the regex cat.
Having been an implication-based usage for so long, "fixing" it would just break UX. Thus I redacted my last comment.
Thus I redacted my last comment.
Well that wrangled continuity somewhat for future readers, so just for the record, SlySven above reacted to the suggestion of adding a QString::trimmed() to the pattern text.
Mangled may be the word you're looking for. The deleted Comment is as follows:
Why not apply QString::trimmed() to the pattern text?
Regex has character classes, as well as the typical escape sequences to match characters. Isn't it better to force explicit patterns than to allow for ambiguous or implied ones?
Only just spotted that you are talking about aliases - of course the same issue is present in several of the trigger types...
Does a space after $ really make sense in our context? I don't think it does, we should just strip it automatically for better UX.
Well if it's a literal escaped $ then SlySven has a point for example.
I can't be sure if there could be other cases still, so I didn't suggest it.
Since we already have to make sure the last character before any spaces is $ would it be that much more difficult to make sure the one before it is not \, and thus it's not an escaped $?
Strip spaces if the last two characters are (anything but \)$ and if the last two characters before the spaces are \$ then don't strip them.
Do we only have this problem after unescaped dollar signs or do we need to tackle any and all surrounding whitespace?
Yeah, I think we can all agree to do it automatically if it a case of a literal line ending. Similarly same for ^. In cases where what the user might want is at least a little bit ambiguous we can throw a warning, but this is pretty foul proof.
Not with my laptop atm to code it, but if anyone else want to give it a go feel free.
Since we already have to make sure the last character before any spaces is $ would it be that much more difficult to make sure the one before it is not
\, and thus it's not an escaped $?
Well I am no regex pro but clearly the character before that could be another slash, rendering the second slash a literal slash and the dollar sign an end of line marker again..
Then again, the suggested solution seems better than status quo indeed.
then check one more character back if it is a backslash. Just means we have to take it one step further.
Consider ^\\\\\\\\\\$
I mean yeah, we could continue to craft unlikely examples we might miss, but let's not lose track of the actual goal of making things better =)
While trimming automatically would solve issue for $, still some triggers and aliases might have space at the end, unintentionally. I would say that in most cases this will be undesired... Universal solution would be to add some hint.
Another option, maybe not prettiest, but definitely will give good hint, would be to give actual text some background different than underlying one. Possibly only when it ends or start with whitespace characters.
Most helpful comment
I mean yeah, we could continue to craft unlikely examples we might miss, but let's not lose track of the actual goal of making things better =)