Girish
Using `regex_replace_all` I am tryign to do the following:
Given a `tl` which has ` (a,b'x',{de}'y',f)` I want to get `(,x,y,)`. Meaning, I want to keep only the things between `' '` and the symbols `,` , `(` and `)`. I can delete things between `' '` by using `('.*?')` and I thought `[^('.*?')]` will serve the purpose, but it doesn't work.
I also tried ` ^(?!.*('.*?'))` for deleting everything but `'...'`, this too doesn't work.
The characters may be Unicode characters. Please help me in extracting this.
I have asked this question here: [https://stackoverflow.com/questions/62319853/regex-matching-complement-of-a-group]
Top Answer
Skillmon
The following code doesn't handle outer parenthesis and assumes a few things:
- braced groups should be ignored even if they contain two ticks
- there are no commas between two ticks (so each "ticked" item is inside *one* clist item)
- there is at most *one* ticked item inside *one* clist item
- the category code of the ticks doesn't change
- inner parenthesis which are not in between two ticks shouldn't be kept
If you're ok with that (and perhaps strip the outer parenthesis before hand and re-add them later -- but I could include them in my code, if you so wish) you could use the following expandable code.
```
\documentclass[]{article}
\ExplSyntaxOn
\scan_new:N \s_girish_stop
\prg_new_conditional:Npnn \girish_if_contains_two_ticks:n #1 { TF }
{
\__girish_if_contains_two_ticks:w #1 '' \s_girish_stop
\prg_return_false:
\prg_return_true:
}
\cs_new:Npn \__girish_if_contains_two_ticks:w #1 ' #2 ' #3 \s_girish_stop
{
\tl_if_empty:nTF { #3 }
}
\cs_new:Npn \__girish_filter_results:n #1
{
\exp_not:o { \use_none:n #1 }
}
\cs_new:Npn \__girish_filter_ticks_extract:w #1 '
{
\__girish_filter_ticks_extract_auxi:w \q_mark
}
\cs_new:Npn \__girish_filter_ticks_extract_auxi:w #1 ' #2 \s_girish_stop
{
\exp_after:wN \__girish_filter_output:nw \exp_after:wN
{ \exp_after:wN , \use_none:n #1 }
}
\cs_new:Npn \__girish_filter_output:nw #1 #2 \__girish_filter_results:n #3
{
#2 \__girish_filter_results:n { #3 #1 }
}
\cs_new:Npn \__girish_filter_ticks:n #1
{
\girish_if_contains_two_ticks:nTF { #1 }
{ \__girish_filter_ticks_extract:w #1 \s_girish_stop }
{ \__girish_filter_output:nw { , } }
}
\cs_new:Npn \girish_filter_ticks:n #1
{
\clist_map_function:nN { #1 } \__girish_filter_ticks:n
\__girish_filter_results:n {}
}
\cs_new_eq:NN \girishfilter \girish_filter_ticks:n
\ExplSyntaxOff
\begin{document}
\girishfilter{a,b'x',{de}'y',f}
\end{document}
```
![noregexneeded.png](/image?hash=6a917eda2502c864a6c18de7ae998b9e2098e16da0518bbb6d0f22849cd2c3fb)