我有文本文件,我想搜索具有特定部分字符串的行,并仅显示包含这些字符串的行
请在这个问题上帮助我 非常感谢你们的大力帮助 我很好地在这个论坛上得到了帮助。请看看 你是伟大的人 请帮帮我 在这一行帮助只存在
这些行必须由任何字符串搜索,在这种情况下,pleas
和"帮助"。不需要区分大小写。
请在这个问题上帮助我 我很好地在这个论坛上得到了帮助。请看看 请帮帮我
我已经使用过这种模式,但对我来说效果很好
(?-s)(?=.*plea)(?=.*help).*
答案 0 :(得分:3)
转到搜索 - >查找(Ctrl + F)。
在“查找内容”文本框中输入由管道分隔的搜索字词,例如“apple | juice”。
答案 1 :(得分:1)
在notepad++
中,在搜索框中使用please|help
并将其设置为正则表达式。 |
搜索或请求帮助,因为它是或运营商。确保检查换行符并忽略大小写复选框。
请查看此网站以更加熟悉正则表达式:http://www.regular-expressions.info/tutorial.html
var matches = document.querySelector("#example")
myRe = /please|help/ig;
while ((myArray = myRe.exec(matches.textContent)) !== null) {
var len = myArray[0].length;
var startIndex = myArray.index;
setSelectionRange(matches, startIndex, startIndex+len);
replaceSelectionWithHtml('<span class="highlight">'+myArray[0]+'</span>');
}
//courtesy to Tim Down
function setSelectionRange(el, start, end) {
if (document.createRange && window.getSelection) {
var range = document.createRange();
range.selectNodeContents(el);
var textNodes = getTextNodesIn(el);
var foundStart = false;
var charCount = 0, endCharCount;
for (var i = 0, textNode; textNode = textNodes[i++]; ) {
endCharCount = charCount + textNode.length;
if (!foundStart && start >= charCount
&& (start < endCharCount ||
(start == endCharCount && i <= textNodes.length))) {
range.setStart(textNode, start - charCount);
foundStart = true;
}
if (foundStart && end <= endCharCount) {
range.setEnd(textNode, end - charCount);
break;
}
charCount = endCharCount;
}
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (document.selection && document.body.createTextRange) {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(true);
textRange.moveEnd("character", end);
textRange.moveStart("character", start);
textRange.select();
}
}
function replaceSelectionWithHtml(html) {
var range;
if (window.getSelection && window.getSelection().getRangeAt) {
range = window.getSelection().getRangeAt(0);
range.deleteContents();
var div = document.createElement("div");
div.innerHTML = html;
var frag = document.createDocumentFragment(), child;
while ( (child = div.firstChild) ) {
frag.appendChild(child);
}
range.insertNode(frag);
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
range.pasteHTML(html);
}
}
function getTextNodesIn(node) {
var textNodes = [];
if (node.nodeType == 3) {
textNodes.push(node);
} else {
var children = node.childNodes;
for (var i = 0, len = children.length; i < len; ++i) {
textNodes.push.apply(textNodes, getTextNodesIn(children[i]));
}
}
return textNodes;
}
.highlight{
background-color: midnightblue;
color: white;
}
<div id="example">Please help me in this issue Thanks a lot for great help I receive help in this forum in great way. Please have a look You are great people Help me please in this line help is only exists these are some lines as an example these lines have to be searched by any string no case sensitive is required in search process
</div>
在JS中查看此示例。它的工作方式相同: