Regex replace in list processing

  • Автор темы Автор темы zeus
  • Дата начала Дата начала

zeus

Client
Регистрация
03.07.2012
Сообщения
99
Реакции
21
Баллы
18
Hello,

It would be a nice feature to have regex replace option in list processing.
Now there is option to delete lines that match a certain regex..but what if I want to replace certain text in the list content.


workaround is to merge list to variable and then perform regex replace.but it doesnt work well in all cases.
 
I will explain it with an example.
we have a list with 2 items :
[0] = <tab>content<tab>content1</tab>Rand</tab>Precious stuff1
[1] = <tab>some stuff<tab>random</tab>unwanted<tab>Precious stuff2

suppose I have a list with these two content stored. How do I extract only the important part that I need?

if I merge it to a single variable and remove all content between <tab> and </tab> it wont work as it will remove the important content als. So I will have to remove it as a list item separately with regex :
<tab>.*</tab>

but right now we don't have this feature in ZP.
Hope it makes sense.
 
I solved this using c# but it would be nice to have it built-in:

PHP:
Развернуть Свернуть Копировать
var contentlist = project.Lists["Content"];
var contentfinal = project.Lists["contentfinal"];
var done = "done";
lock(SyncObjects.ListSyncer)
{
	foreach(var content in contentlist)
	{
		var output = System.Text.RegularExpressions.Regex.Replace(content,@"regexhere", "");
		contentfinal.Add(output);
	}
}
return done;

EDIT: the above code requires .NET 4.5.
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)