[tw5] Re: Regex Character Classes not working in search-replace

2021-08-07 Thread John Davis
Awesome, thanks.  I had tried that but messed up the search-replace syntax, 
I didn't realize the angle brackets would replace the square brackets and 
was using both:

[search-replace:i:regexp[],[$2, $1]]

Much appreciated.
On Saturday, August 7, 2021 at 3:42:06 AM UTC-4 saq.i...@gmail.com wrote:

>  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. 
>
>
> You cannot have the characters [ and ] inside a literal operand to a 
> filter operator.
> The workaround is to define the regular expression as a variable and then 
> use the variable as the operand.
>
> Pseudo code below.
>
> \define myregexp() ((?:.*\s)|^)([a-zA-Z0-9_]+$)
>
> \define compare-by-last-name-with-character-class()
> [search-replace:i:regexp,[$2, $1]]
> \end
>
>

-- 
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/482ec638-e4fb-4e6f-a93c-e71924cbea04n%40googlegroups.com.


[tw5] Regex Character Classes not working in search-replace

2021-08-07 Thread John Davis
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. My actual goal is to replace \w with something like [^ 
], because where it's breaking is last names that include apostrophes.

This is an example that can be inserted in a new Tiddler to demonstrate the 
issue; the first list is the way it's currently working (you can see 
Vincent D'Onofrio is out of order and not in LastName, FirstName format) 
and the second list is broken due to the character class issue:



\define compare-by-last-name()
[search-replace:i:regexp[((?:.*\s)|^)(\w+$)],[$2, $1]]
\end
\define compare-by-last-name-with-character-class()
[search-replace:i:regexp[((?:.*\s)|^)([a-zA-Z0-9_]+$)],[$2, 
$1]]
\end


<$set name="listOfNames" value="[[Charlie Cox]] [[Vincent D'Onofrio]] 
[[Deborah Ann Woll]] [[Elden Henson]] [[Royce Johnson]] [[Geoffrey Cantor]] 
[[Jay Ali]] [[Jon Bernthal]] [[Stephen Rider]] [[Wilson Bethel]] [[Ayelet 
Zurer]] [[Peter McRobbie]] [[Amy Rutberg]] [[Elodie Yung]] Awkwafina" >



<$list filter="[enlistsortsub]">
<$link><$text 
text={{{[search-replace:i:regexp[(.*)(\s\w+$)],[$2, 
$1]]}}}/>





<$list 
filter="[enlistsortsub]">
<$link><$text 
text={{{[search-replace:i:regexp[(.*)(\s\w+$)],[$2, 
$1]]}}}/>






-- 
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/f0c90269-244b-4f1b-ad2f-68c2a3e33633n%40googlegroups.com.