Retrieve a line starting with x and ending with y

First of all, I did a search on this issue and was able to find how to use something like String.Split () to retrieve a string based on a condition. However, I could not find how to extract it based on the final condition. For example, I have a file with links to images: http://i594.photobucket.com/albums/tt27/34/444.jpghttp://i594.photobucket.com/albums/as/asfd/ghjk6.jpg You will notice that all images start with http://and end with .jpg. However, .jpg is replaced by http: // without a space, which makes this a bit more complicated.

So basically I'm trying to find a way (Regex?) To extract a line from a line that starts with http: // and ends with .jpg

+3
source share
5 answers

Regex - . , Regex Buddy. , , . :

(http://.+?\.jpg)

, , , , , .


.


, -, , http:// .jpg . URL- , :

(http://[^\s]+\.jpg)

: " , http:// .jpg, , ".

+4
    Regex RegexObj = new Regex("http://.+?\\.jpg");
Match MatchResults = RegexObj.Match(subject);
while (MatchResults.Success) {
    //Do something with it 
    MatchResults = MatchResults.NextMatch();
     }
+2

, ".jpg". , , .jpg , . , , .

, :

public void SplitTest()
{
    string test = "http://i594.photobucket.com/albums/tt27/34/444.jpghttp://i594.photobucket.com/albums/as/asfd/ghjk6.jpg";
    string[] items = test.Split(new string[] { ".jpg" }, StringSplitOptions.RemoveEmptyEntries);
}

...

+1

LINQ http: , jpg.

 var images = from i in imageList.Split(new[] {"http:"}, 
                                     StringSplitOptions.RemoveEmptyEntries)
              where i.EndsWith(".jpg")
              select "http:" + i;
+1
source

Regex will work very well for this. Here is an example in C # (and Java) for Regex

0
source

Source: https://habr.com/ru/post/1738903/


All Articles