我有一个学生身份证的清单,连同成绩,三个考试结果,每个学生都收到。我创建了一个fileReader来读取本地文档中的文本,并将结果存储在一个变量中。我有一个检索所需信息的正则表达式,这些信息应该可以工作,但返回null。
所述信息存储为;
C00695260
93
76
86 试图使用的regex是,/C\d{8}\s\d{2}\d?\s\d{2}\d?\s\d{2}\d?/g,它突出了我想要的崇高而不是在程序或浏览器控制台中想要的东西。它像预期的那样工作到之后,/C\d{8}\s\d{2}\d?\s/g,,但我不知道为什么。如果我做错了什么,这是我的第一篇文章。
这个剂量没用
var textIn;
var r =/B\d{8}\s\d{2}\d?\s\d{2}\d?\s\d{2}\d?/g;
var print;
//crete a function the read listen fot the file to change
document.getElementById('openFile').addEventListener('change', function(){
var reader = new FileReader();
reader.onload = function(){
textIn = this.result;
print = textIn.match(r);
document.getElementById('Filecontents').textContent = print;
}
reader.readAsText(this.files[0]);
})这行得通!
var textIn;
var r =/(B\d{8})\s/g;
var print;
//crete a function the read listen fot the file to change
document.getElementById('openFile').addEventListener('change', function(){
var reader = new FileReader();
reader.onload = function(){
textIn = this.result;
print = textIn.match(r);
document.getElementById('Filecontents').textContent = print;
}
reader.readAsText(this.files[0]);
})发布于 2016-12-09 16:10:05
您需要这样的东西:(C{8})s(\d{1,3})\s(\d{1,3})\s(d{1,3})
(C{8})=一个编号被捕获的组,该组寻找一个跟随8位数的"C“
S=空白
(\d{1,3}) =查找1-3位数的已编号捕获组
重复


https://stackoverflow.com/questions/41064336
复制相似问题