我有一个大型文本文档,其中填充了随机单词、网址、电子邮件地址等。示例:“word 2014 john@doe.com http://www.example.com/ http://example.com/image.gif ”,但它看起来可能会有所不同,可能会有换行符、多个空格、制表符等。并且数据可能很快就会变得巨大(这是一种书签服务,因此数据始终以图像、文本和超链接)。
文本文档中内容的另一个示例(我用于测试的):
http://movpod.in/images3/MovPod-logo.png
https://dt8kf6553cww8.cloudfront.net/static/images/developers/chooser-drawing-vfln1ftk6.png
http://xregexp.com/assets/regex_cookbook.gif
asd asd ad feaf
apa
http
Run Code Online (Sandbox Code Playgroud)
我想将所有这些字符串包装在标签中,并且能够定位图像、超链接、电子邮件和字符串。我尝试了不同的方法,但不确定哪种方法最好,而且还有一个我不完全理解的正则表达式。
最终结果应该是:
<span>word</span>
<span>2014</span>
<a class="mail" href="mailto:john@doe">john@doe.com</a>
<a class="url" href="http://www.example.com/">http://www.google.com/</a>
<a class="img" href="http://example.com/image.gif">http://example.com/image.gif</a>"
Run Code Online (Sandbox Code Playgroud)
匹配。然而,这种方法并不能保持文本顺序完整,但它确实有效。
arr = data.split("\n");
for (i = 0; i < arr.length; i++)
{
arr2 = arr[i].split(' ');
for (j = 0; j < arr2.length; j++)
{
if (arr2[j].match(/(.gif|.png|.jpg|.jpeg)/))
{
ext = arr2[j].substr(-4);
ext = ext.replace(".","");
imgs += '<a class="img '+ext+'" href="'+arr2[j]+'">'+arr2[j]+'</a>';
}
else if (arr2[j].match(/(http:)/))
{
urls += '<a class="url" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Electron 创建我自己的http://meetfranz.com/版本。
\n\n该应用程序应允许多个 URL(例如https://messenger.com/和https://gmail.com/)可见,并具有选项卡式界面。
\n\n我尝试过生成 Webview 和 BrowserWindow。
\n\n我之前也尝试过使用 iFrame,但这是行不通的。
\n\n关于实现允许 cookie/https 的选项卡式最小浏览器界面的最佳方法有什么想法吗?
\n\n索引.html
\n\n<html>\n<head>\n <style>\n webview {\n display: inline-flex; \n width: 800px; \n height: 600px;\n }\n </style>\n</head>\n<body>\n <form name="form">\n <input name="input" placeholder="https://messenger.com/" value="https://messenger.com">\n <button type="submit">submit</button>\n </form>\n <div class="tabs">\n </div>\n <div class="webviews">\n </div>\n <!--<webview src="https://messenger.com/" autosize="on" nodeintegration="on" disablewebsecurity="on" webpreferences="allowRunningInsecureContent"></webview>-->\n <script type="text/javascript">\n require(\'./app.js\')\n </script>\n</body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n\nmain.js
\n\nconst {app, BrowserWindow, BrowserView} …Run Code Online (Sandbox Code Playgroud)