Notepad++ regex replace named groups
Asked Answered
R

1

14

I try replace author Full name with article title I have a list of articles, similar like this:

  1. Albershein P., Nevis D. J. A method for analysis of sugars in plant cell wall polysaccharides by gasliquid chromatography // J. Carbohydrate Research. – 1967. – Vol. 5, № 3. – Р. 340–345.

And I have Regex for it

(?'n1'^\d{3}\. )(?'n2'(?:(?:[A-ZА-Я][-a-zćа-я ]+)?([A-ZА-Я][-a-zćа-я]+\xA0[A-ZА-Я]\.(?:\xA0[A-ZА-Я]\.){0,2}\,?)(?: \[et al\])? ?)+)(?'n3' [^\/]+[\/]{2})

but replace like

\k{n1} 

or

\k'n1'

doesnt work

we try this in perl but have the same result

Rois answered 10/11, 2015 at 15:5 Comment(9)
Try just numeric group index \1 or $1. Groupname would be \g<n1>, ${n1} in replace or maybe \k{n1},\g{n1} but none seems to work in np++.Schoolmistress
In Perl you might try $+{name} on the replacement side, but it should be in the form of eval s///eg (not sure about the eval)Eclogite
\1 \2 ... working fine in simple samles, but in this case it dosent work (you can try)Rois
In official help np++ I found what I need but it doesnt work Details here docs.notepad-plus-plus.org/index.php/Regular_ExpressionsRois
I cannot get this regex working at regex101.comWarms
regex101.com is a really powerful regex platform. The explanation for the regex is pooooooooowerful!Warms
how should I use regex to replace this reference? [23] D. Spina, M.-H. Peetz, and M. de Rijke. Active learning for entity filtering in microblog streams. In Proceedings of the 38th International ACM SIGIR Conference on Research and Development in Information Retrieval, SIGIR ’15, pages 975 978. ACM, 2015.Warms
@Warms Which result you are expect to get?Rois
Regex: ^\[?(?<n1>\d{1,3}\.?)\]? (?<n2>((and )?(-?[A-Z]\. ?)+(de )?[A-Z][a-Z]+[,.] )+)(?<n3>.+) Replace with: $+{n1} $+{n3} // $+{n2} Output: 23 Active learning for entity filtering in microblog streams. In Proceedings of the 38th International ACM SIGIR Conference on Research and Development in Information Retrieval, SIGIR ’15, pages 975 978. ACM // D. Spina, M.-H. Peetz, and M. de Rijke. Rois
K
27

Try using in regex (?<groupname>something to match)

And in replacement: $+{groupname}

Kuchen answered 8/1, 2017 at 11:25 Comment(3)
ensure you selected "Match case" and "Regular expression" in the Replace tab.Warms
@Warms I do not need Match case. Question was only about named groups which in official notepad++ documentation described incorrect.Rois
@Jakub Binkowski Can you please elaborate on this usage? I can't find it in the documentation. I noticed that I can use a single {groupname} for conditionals, but I have to prefix it with $+ if I want to use the content in replacementWomera

© 2022 - 2024 — McMap. All rights reserved.