Delete lines Regex

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

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 263
Баллы
113
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

arve_lek

Client
Регистрация
05.06.2012
Сообщения
14
Благодарностей
2
Баллы
3
Thank u Radzhab but the code doesn't seem to work. It did not delete anything.
 

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 021
Благодарностей
1 385
Баллы
113
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

arve_lek

Client
Регистрация
05.06.2012
Сообщения
14
Благодарностей
2
Баллы
3
Thank u Alexmd it's works

but I have to changed

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

into:

tabindex="0">1.00</span>

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

arve_lek

Client
Регистрация
05.06.2012
Сообщения
14
Благодарностей
2
Баллы
3
@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]
 

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 021
Благодарностей
1 385
Баллы
113
Hi!
Try just removing all html tags from line
replace this code
Regex.Match(x, "(?<=tabindex="0">).*?(?=</span>)").Value
with this one
Regex.Replace(x, @"<.*?>", "").Trim()
 

arve_lek

Client
Регистрация
05.06.2012
Сообщения
14
Благодарностей
2
Баллы
3
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.
 

Alexmd

Client
Регистрация
10.12.2018
Сообщения
1 021
Благодарностей
1 385
Баллы
113
So give an example of your whole string. There is variant to split value by whitespace and choosing the value you need by index.
Regex.Replace(x, @"<.*?>", "").Trim().Split(' ')[1].Trim()
 

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