Delete lines Regex

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

arve_lek

Client
Регистрация
05.06.2012
Сообщения
14
Реакции
2
Баллы
3
Hello, It is possible to delete lines not matching regex ?

tabindex="0">1,00</span>
tabindex="0">22,00</span>
tabindex="0">22,50</span>
tabindex="0">39,90</span>
tabindex="0">40,00</span>
tabindex="0">42,00</span>
tabindex="0">142,00</span>
tabindex="0">1142,55</span>

I want to delete all lines with number more than 39,90 or equal
 
  • Спасибо
Реакции: Radzhab
C#:
Развернуть Свернуть Копировать
var lst = project.Lists["list1"].ToList();
var z = lst.OrderBy(x => Convert.ToDouble(Regex.Match(x, "(?<=>).+(?=\\<)").Value)<=39.90).ToList();
project.Lists["list1"].Clear();
project.Lists["list1"].AddRange(z);
 
  • Спасибо
Реакции: arve_lek
Thank u Radzhab but the code doesn't seem to work. It did not delete anything.
 
arve_lek, try this
C#:
Развернуть Свернуть Копировать
var lst = project.Lists["list1"].ToList();
project.Variables["max"].Value = "39.90";// here is your variable from project
var z = lst.Where(x => Convert.ToDouble(Regex.Match(x, "(?<=>).+(?=\\<)").Value)>=Convert.ToDouble(project.Variables["max"].Value)).ToList();
project.Lists["list1"].Clear();
project.Lists["list1"].AddRange(z);
 
  • Спасибо
Реакции: arve_lek
Thank u Alexmd it's works

but I have to changed

tabindex="0">1,00</span>

into:

tabindex="0">1.00</span>

:-)
 
Последнее редактирование:
@Alexmd

I'm sorry that I'm bothering you on Sunday, I hope u spending time far away from computer :)

1. What if I have a row something like this:

<div class="msa3_z4 _9c44d_2K6FN"><span class="_1svub _lf05o" tabindex="0">2.00</span><i class="_9c44d_2UYuR _9c44d_1DKTg">

I tried with regex= (?<=tabindex="0">).*?(?=</span>)

C#:
Развернуть Свернуть Копировать
var z = lst.Where(x => Convert.ToDouble(Regex.Match(x, "(?<=tabindex="0">).*?(?=</span>)").Value)>=Convert.ToDouble(project.Variables["max"].Value)).ToList();

Compiling code of Error in action "CS1002"(;)". [Row: 2; Column: 97]
 
IF I will delete all html tags than in the same line will be more than one number:

99.8% 39.90 46.89

There is no possible to use my regex: (?<=tabindex="0">).*?(?=</span>) ? In regular expressions designer is working great.
 

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