如何从textarea中提取图像或视频路径?

时间:2020-12-16 21:24:07

I am having one textarea in which i will enter some text and this textarea will contain image path or video link.for eg:https://www.gravatar.com/avatar/e514b017977ebf742a418cac697d8996?s=48&d=identicon&r=PG or any video link.

我有一个textarea,我将在其中输入一些文本,此textarea将包含图像路径或视频链接。例如:https://www.gravatar.com/avatar/e514b017977ebf742a418cac697d8996?s = 48&d = identicon&r = PG或任何视频链接。

I want to extract image path or video path from text when i receive the value from my textarea on my controller.

当我从控制器上的textarea接收值时,我想从文本中提取图像路径或视频路径。

My table which will store Textarea details:

我的表格将存储Textarea的详细信息:

Details:
Id,Description,image/videopath

so to store in my table i want to extract my image path or video path from my textarea.

所以要存储在我的表中我想从我的textarea中提取我的图像路径或视频路径。

Screenshot:如何从textarea中提取图像或视频路径?

Here in the above screent shot i am having one textarea which contain some text and link of my image with preview available below.

在上面的screent镜头中我有一个textarea,其中包含我的图像的一些文本和链接以及下面的预览。

Below this i am having one submit button which will post this textarea value to my controller.

在这下面我有一个提交按钮,它将这个textarea值发布到我的控制器。

My View code:

我的观看代码:

 @using (Html.BeginForm("GetTextAreaData", "MyController", FormMethod.Post))
        {
          <textarea id="details" name="textAreaDetails"></textarea>
                  <input type="submit" value="Finish" />
        }

My Controller:

 public ActionResult GetTextAreaData()
        {
            var textareaData=Request["textAreaDetails"];//get textarea details by name
            //Now how to extract image or video path from this???
        }

1 个解决方案

#1


You can use a regular expression:

您可以使用正则表达式:

var someTextWithOrWithoutUrl = ".... "

var match =  Regex.Match(someTextWithOrWithoutUrl , @"(https?://\S+)");
var url = match.Success ? match.Groups[1] : null;

This will will work for http as well as https.

这将适用于http和https。

#1


You can use a regular expression:

您可以使用正则表达式:

var someTextWithOrWithoutUrl = ".... "

var match =  Regex.Match(someTextWithOrWithoutUrl , @"(https?://\S+)");
var url = match.Success ? match.Groups[1] : null;

This will will work for http as well as https.

这将适用于http和https。