On Saturday, August 7, 2021 at 12:24:28 AM UTC-7 john....@gmail.com wrote: > I'm using a macro and search-replace to convert a list of FirstName > LastName to LastName, FirstName. It works fine with the shortcut class \w, > but if I replace that with [a-zA-Z0-9_] it breaks, when logically those > should be the same.
The problem is that *regex syntax uses square brackets* (to specify character classes), and *TiddlyWiki filter syntax also uses square brackets* (to specify literal text operands), and* the filter parser does not allow nesting of brackets*. Thus, when you use the character class regex syntax, it breaks the filter syntax due to nesting of square brackets. This is noted here: https://tiddlywiki.com/#regexp%20Operator, where it says: *The filter syntax makes it impossible to directly specify a regular expression that contains square brackets. The solution is to store the expression in a variable. * The workaround is to put your regex patterns into variables, and then use those variables in the filter, like this: \define compare-by-last-name-with-character-class() <$vars search="((?:.*\s)|^)([a-zA-Z0-9_]+$)" replace="$2, $1"> [<currentTiddler>search-replace:i:regexp<search>,<replace>] </$vars> \end Note that is this particular use-case, it's not strictly necessary to put the "replace" pattern into a variable, since it doesn't actually use square brackets in the syntax. However, I find that putting both the search pattern and the replacement pattern into variables makes the filter syntax more consistent and easier to read. enjoy, -e -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/067903e8-971c-480c-bcc9-7fc6d1a1ac1en%40googlegroups.com.