我应该使用什么正则表达式来获取css类的内容并存储它们?
What regex shall I use to fetch the content of css classes and store them?
您好,我已经创建了一个文本框,用于从PDF中复制内容并接受富文本格式的内容。
<html>
<head>
<link rel="stylesheet" type="text/css" href="Theme.css">
</head>
<body>
<div>
<textarea id="ta" onpaste="functionItalic(event)" class="foostyle2"></textarea>
</div>
<div>
<span style="font-weight: bolder; font-size: 20px;">
<span id="1">Karan's</span>
</span>
<span style="font-weight: bolder; font-size: 24px; font-style: italic;">test</span>
</div>
<script>
function functionItalic(pasteEvent)
{
var textareacont = (pasteEvent.originalEvent || pasteEvent).clipboardData.getData("text/html");
console.log(textareacont);
}
</script>
</body>
</html>
当我在控制台上打印内容时(内容是对于烟雾保护的装配座位,常见的),我发现PDF中的内容包含像这样的css类和html标签
注:此代码是在执行console.log(textareacont);
时获得的对于防烟总成座位,一般采用
CSS Tweaking.html (line 19)
<html>
<head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><style>
<!--
br
{
mso-data-placement:same-cell;
}
table
{
mso-displayed-decimal-separator:"'.";
mso-displayed-thousand-separator:"', ";
}
tr
{
mso-height-source:auto;
mso-ruby-visibility:none;
}
td
{
border:.5pt solid windowtext;
}
.NormalTable{cellspacing:0;cellpadding:10;border-collapse:collapse;mso-table-layout-alt:fixed;border:none; mso-border-alt:solid windowtext .75pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-border-insideh:.75pt solid windowtext;mso-border-insidev:.75pt solid windowtext}
.fontstyle0
{
font-family:Times-Roman;
font-size:10pt;
font-style:normal;
font-weight:normal;
color:rgb(0,0,0);
}
.fontstyle1
{
font-size:12pt;
font-style:normal;
font-weight:normal;
color:rgb(0,0,0);
}
.fontstyle2
{
font-family:Times-Italic;
font-size:10pt;
font-style:italic;
font-weight:normal;
color:rgb(0,0,0);
}
-->
</style></head><body>
<!--StartFragment-->
<span class="fontstyle0">For </span><span class="fontstyle2">smoke-protected assembly seating</span><span class="fontstyle0">, the </span><span class="fontstyle2">common</span>
<br style=" font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">
<!--EndFragment-->
</body>
</html>
我想要的是,我想要获得css类的属性名称。fontstyle1,。fontstyle2,。字符串格式的fontstyle3,有人说这可以通过RegEx谁能告诉我什么将是RegEx,我需要使用以便在字符串中存储。fontstyle类。我试过几个,但都不起作用。换行符、回车符和制表符换行符是字符串的一部分,只出现在类中。
如果有人知道另一种方法来存储。fontstyle类的内容在字符串。我不太懂正则表达式
你可以使用这个正则表达式
/'.fontstyle'd+'s*'{['w's-:;,()]*'}/g
我不确定我是否给了太多的帮助,但既然它已经编码了…
// The regular expression
var regularExp = /'.fontstyle'd+'s*'{['w's-:;,()]*'}/g;
var match;
// .fontstyle will be stored in fontstyle_list[]
var fontstyle_list = [];
// Finds all match
while (match = regularExp.exec(/*The css file (converted to string) should go here*/)) {
// Adds every match into fontstyle_list
fontstyle_list.push(match[0]);
}
// Iterate through every element in fontstyle_list
for (var i in fontstyle_list){
// prints out each .fontstyle{}
document.write(fontstyle_list[i] + "<br />"); // document.write() is unsafe and should only be used for testing
// add your codes here
}
2。另外
在使用子字符串检索每个以'开头的元素之前,你可以将css解析成一个对象。fontstyle '
- 将css解析为对象。参考https://stackoverflow.com/a/14865690/6943913
- 对于步骤2中的每个元素,执行
<eachElement>.substring(0, 10) === ".fontstyle"
- 对于第3步中返回true的每个操作,将元素复制到另一个列表
遍历步骤1中对象的所有元素
*免责声明:上面的步骤只是为了说明程序逻辑,可能需要做一些调整以适应实际场景
相关文章:
- 使用Angular存储用户以前是否选中过复选框,然后再调用它的最佳方式是什么
- 存储数据的最佳方式是什么,以便与jquery一起使用
- 在 React JS 中,什么时候应该使用存储而不是直接操作视图的状态
- 在 Windows 现代(地铁)UI 应用中存储图像文件和音频文件的方法是什么?
- Chrome/Tampermonkey 用户脚本存储在文件系统上的什么位置
- 在JavasciptMVC中存储常量值的最佳方式是什么
- Angular:将对象存储在服务中以在视图中显示和将crud函数存储到服务器的最佳方式是什么
- 将密码存储在Javascript变量中的安全含义是什么
- listener() 在 Redux 存储中做什么
- 谷歌浏览器同步存储“获取”命令运行什么顺序
- 在 Javascript 中存储对象的当前状态的最佳实践是什么?
- Flux,ReactJS,架构的存储部分是什么
- 与 API 一起使用时,将 Date 对象存储在数据库中的最佳实践是什么
- 如果取消对本地存储的写入,会发生什么情况
- 我应该在 Laravel 5 中存储 JS 的什么位置
- 如果我存储缓存并且已达到缓存限制会发生什么
- 在 JavaScript 中存储非常大的二进制数的最佳方法是什么?
- 全局变量存储在 Node.JS 中的什么位置?节点中是否有类似窗口的对象
- 此对象的键存储的格式是什么?%00*%00_data.
- 我应该存储什么来识别NodeJS中的Interval