E
E
EshkinKat2013-12-26 14:45:46
Regular Expressions
EshkinKat, 2013-12-26 14:45:46

How to compose regex for C#?

There is a line snippet:

много таких кусков вверх
<div class="commentthread_comment_text"  id="comment_content_546947">
        TEXT TO FIND			</div>
          </div>
          <div class="forum_comment_permlink">
                <a href="#c8645777">#34</a>
много таких кусков вниз

You need to find TEXT TO FIND.".*" (without quotes) only goes up to the first new line. And the application works in general incomprehensibly.
You need to push off from #34 (only it is known and there is only one match in the line [#c][0-9]{1,7}.{2}[#34][]). The remaining numbers are unknown and there are many of them in the string.
PS What is the best way to cut the desired text from a string?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OlegTar, 2013-12-26
@EshkinKat

You just need to start from ">#34<?a>up to cut off to the nearest
StringBuilder stringb= new StringBuilder(string_);
int pos = stringb.ToString().IndexOf(@""">#34");//"
stringb.Remove(pos, stringb.ToString() - pos);//Убираем всё, что после
pos = stringb.ToString().LastIndexOf(@"<div class=""commentthread_comment_text""  id=""comment_content_546947"">");//Ищём "div class="... выше "">#34
stringb.Remove(0, pos);//Убираем всё, что выше
string_ = stringb.ToString();

D
Dmitry Guketlev, 2013-12-26
@Yavanosta

regexr.com?37pou
regexr.com?37pp1
But in general it is better to parse with special parsers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question