if i have a textbox with severals urls
rapidshare.com/files/379028801/foo.bar.HDTV.XviD-LOL.avi
rapidshare.com/files/379182651/foo.bar.720p.HDTV.X264-DIMENSION.mkv
rapidshare.com/files/379180004/foo.bar.720p.HDTV.X264-DIMENSION.part1.rar rapidshare.c开发者_高级运维om/files/379180444/foo.bar.720p.HDTV.X264-DIMENSION.part2.rar rapidshare.com/files/379181251/foo.bar.720p.HDTV.X264-DIMENSION.part3.rar rapidshare.com/files/379181743/foo.bar.720p.HDTV.X264-DIMENSION.part4.rar
i need a the files name and its urls
textbox2.text =
foo.bar.HDTV.XviD-LOL.avi
from here
rapidshare.com/files/379028801/foo.bar.HDTV.XviD-LOL.avifoo.bar.720p.HDTV.X264-DIMENSION.part1.rar
from here rapidshare.com/files/379180004/foo.bar.720p.HDTV.X264-DIMENSION.part1.rarand so on
Thanks :)
Well, can't ya just get the string that follows the last / ?
Just get the substring with the beginning "LastIndexOf("/") + 1" and you'll have it, skipping all the regex stuff. It's a single-line solution and it's quicker!
It's something like that:
String filename = ulr.Substring(url.LastIndexOf("/") + 1);
Cheers,
vloo
I could use this regex for getting the file name,
rapidshare.com/files/[0-9]*/(?<name>.*)$
The C# code would look like,
string text= textbox1.Text;
Regex regex = new Regex(@"rapidshare.com/files/[0-9]*/(?<name>.*)$");
MatchCollection matches = regex.Matches(text);
if (matches.Count > 0)
{
string fileName = (from Match match in matches
where match.Success
select match.Groups["name"].Value.Trim());
}
Something like this should do it
String flnam = Regex.Match("rapidshare.com/files/379028801/Fringe.S02E19.HDTV.XviD-LOL.avi",
@".*\/([^/]*)$").Groups[1].Value.ToString();
Console.WriteLine(flnam);
You should be able to search for something like this regex and replace it with "":
rapidshare.com/files/[0-9]*/
For example, in JavaScript:
var fileName = fullUrl.replace(/rapidshare.com\/files\/[0-9]*\//, "");
Note that the \/
escapes the /
which would, in JavaScript, otherwise end the regular expression.
精彩评论