Identifying strings that contain keywords
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How to modify the script highlighting the lines that contain keywords separated by multiple delimiters
I'm not a programmer, but I need to ease my work.
I found a little script that highlights the red lines containing obscene words. Then I manually copy and save the lines just in case.
However, I would like to automate this. I did not find anything similar on the Internet. Therefore, I tried to make a script with my own hands. Here is what I did:
function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre>I failed to replace br with n.
I can select text between words, but how to make the script get all the lines containing stop words.
Then I need to put them in another text block and delete them in the first block.
At first, I wanted the script to sort the lines broken by n containing swear words by the number of swear words, but it is very difficult, I even failed to select the text.
There you need to use something similar to the Levenshtein distance.
I need to at least find out how to get a set of lines of text that contain stop words separated by n. Then I can try to solve the rest of the problem itself.
Input
line of text with words without stopword(two or more)
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words without stopword
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
line of text with words without stopword
output1(Filther words)
line of text with words without stopword(two or more)
line of text with words without stopword
line of text with words without stopword
output2
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
I want to save all messages containing stop words to another tag. Leave only those that do not contain them.
I need for filher lines that contains stopword
javascript html arrays regex
|
show 6 more comments
How to modify the script highlighting the lines that contain keywords separated by multiple delimiters
I'm not a programmer, but I need to ease my work.
I found a little script that highlights the red lines containing obscene words. Then I manually copy and save the lines just in case.
However, I would like to automate this. I did not find anything similar on the Internet. Therefore, I tried to make a script with my own hands. Here is what I did:
function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre>I failed to replace br with n.
I can select text between words, but how to make the script get all the lines containing stop words.
Then I need to put them in another text block and delete them in the first block.
At first, I wanted the script to sort the lines broken by n containing swear words by the number of swear words, but it is very difficult, I even failed to select the text.
There you need to use something similar to the Levenshtein distance.
I need to at least find out how to get a set of lines of text that contain stop words separated by n. Then I can try to solve the rest of the problem itself.
Input
line of text with words without stopword(two or more)
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words without stopword
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
line of text with words without stopword
output1(Filther words)
line of text with words without stopword(two or more)
line of text with words without stopword
line of text with words without stopword
output2
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
I want to save all messages containing stop words to another tag. Leave only those that do not contain them.
I need for filher lines that contains stopword
javascript html arrays regex
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17
|
show 6 more comments
How to modify the script highlighting the lines that contain keywords separated by multiple delimiters
I'm not a programmer, but I need to ease my work.
I found a little script that highlights the red lines containing obscene words. Then I manually copy and save the lines just in case.
However, I would like to automate this. I did not find anything similar on the Internet. Therefore, I tried to make a script with my own hands. Here is what I did:
function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre>I failed to replace br with n.
I can select text between words, but how to make the script get all the lines containing stop words.
Then I need to put them in another text block and delete them in the first block.
At first, I wanted the script to sort the lines broken by n containing swear words by the number of swear words, but it is very difficult, I even failed to select the text.
There you need to use something similar to the Levenshtein distance.
I need to at least find out how to get a set of lines of text that contain stop words separated by n. Then I can try to solve the rest of the problem itself.
Input
line of text with words without stopword(two or more)
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words without stopword
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
line of text with words without stopword
output1(Filther words)
line of text with words without stopword(two or more)
line of text with words without stopword
line of text with words without stopword
output2
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
I want to save all messages containing stop words to another tag. Leave only those that do not contain them.
I need for filher lines that contains stopword
javascript html arrays regex
How to modify the script highlighting the lines that contain keywords separated by multiple delimiters
I'm not a programmer, but I need to ease my work.
I found a little script that highlights the red lines containing obscene words. Then I manually copy and save the lines just in case.
However, I would like to automate this. I did not find anything similar on the Internet. Therefore, I tried to make a script with my own hands. Here is what I did:
function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre>I failed to replace br with n.
I can select text between words, but how to make the script get all the lines containing stop words.
Then I need to put them in another text block and delete them in the first block.
At first, I wanted the script to sort the lines broken by n containing swear words by the number of swear words, but it is very difficult, I even failed to select the text.
There you need to use something similar to the Levenshtein distance.
I need to at least find out how to get a set of lines of text that contain stop words separated by n. Then I can try to solve the rest of the problem itself.
Input
line of text with words without stopword(two or more)
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words without stopword
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
line of text with words without stopword
output1(Filther words)
line of text with words without stopword(two or more)
line of text with words without stopword
line of text with words without stopword
output2
line of text with words and <span style='background-color:red'>stopwords</span>
line of text with words and <span style='background-color:red'>stopwords</span>...<span style='background-color:red'>stopwords</span>(two or more)
I want to save all messages containing stop words to another tag. Leave only those that do not contain them.
I need for filher lines that contains stopword
function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre> function extractText(str,delimiter)
if (str && delimiter)
var firstIndex = str.indexOf(delimiter)+1;
var lastIndex = str.lastIndexOf(delimiter);
str = str.substring(firstIndex,lastIndex);
return str;
const keywordsString = ""+
"stopword|stopword1|stopword2";
const keywords = keywordsString.split(/#/);
const pattern = new RegExp(`($keywords.join('#'))`, 'g');
const phrase = ""+
"I like cake, pie and<br>cookies keyword keyword<br> stopword<br>";
const result = phrase.replace(pattern, match => `<span style='background-color:red'>$match</span>`);
setTimeout(function()
document.getElementById('prep').innerHTML = result;
if (result.indexOf("span") != -1)
alert(extractText(result),'
');
document.getElementById('prex').innerHTML = extractText(result,'<br>');
alert("found");
, 100);<pre id="prep" contenteditable="true"></pre>
<pre id="prex" contenteditable="true"></pre>javascript html arrays regex
javascript html arrays regex
edited Nov 15 '18 at 17:55
Serge
3,31234394
3,31234394
asked Nov 15 '18 at 15:25
lebokywerlebokywer
83
83
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17
|
show 6 more comments
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17
|
show 6 more comments
1 Answer
1
active
oldest
votes
Using the code bellow I take the lines from first blue text area, and separate them in red (bad) and green(good) text areas.
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>In order to replace all occurrences of "<br>" to "n", you can do the following
myString.replace(new RegExp(myDelimiter, 'g'), toReplaceChar)
console example:
>'abc<br>1<br>2<br>3t<br>yyy'.replace(new RegExp("<br>", 'g'), "n")
"abc
1
2
3t
yyy"
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322663%2fidentifying-strings-that-contain-keywords%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using the code bellow I take the lines from first blue text area, and separate them in red (bad) and green(good) text areas.
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>In order to replace all occurrences of "<br>" to "n", you can do the following
myString.replace(new RegExp(myDelimiter, 'g'), toReplaceChar)
console example:
>'abc<br>1<br>2<br>3t<br>yyy'.replace(new RegExp("<br>", 'g'), "n")
"abc
1
2
3t
yyy"
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
add a comment |
Using the code bellow I take the lines from first blue text area, and separate them in red (bad) and green(good) text areas.
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>In order to replace all occurrences of "<br>" to "n", you can do the following
myString.replace(new RegExp(myDelimiter, 'g'), toReplaceChar)
console example:
>'abc<br>1<br>2<br>3t<br>yyy'.replace(new RegExp("<br>", 'g'), "n")
"abc
1
2
3t
yyy"
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
add a comment |
Using the code bellow I take the lines from first blue text area, and separate them in red (bad) and green(good) text areas.
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>In order to replace all occurrences of "<br>" to "n", you can do the following
myString.replace(new RegExp(myDelimiter, 'g'), toReplaceChar)
console example:
>'abc<br>1<br>2<br>3t<br>yyy'.replace(new RegExp("<br>", 'g'), "n")
"abc
1
2
3t
yyy"
Using the code bellow I take the lines from first blue text area, and separate them in red (bad) and green(good) text areas.
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>In order to replace all occurrences of "<br>" to "n", you can do the following
myString.replace(new RegExp(myDelimiter, 'g'), toReplaceChar)
console example:
>'abc<br>1<br>2<br>3t<br>yyy'.replace(new RegExp("<br>", 'g'), "n")
"abc
1
2
3t
yyy"
var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>var myLines = $("#s").val().split("n");
const badWords = ["kaka", "saka", "baka"];
// here we use bKEYWORDb in order to keep whole words only
let myExp = new RegExp("(\b" + badWords.join("\b)|(\b") + "\b)", "g");
var goodLines = ;
var badLines = ;
for (let line of myLines)
if (line.match(myExp))
badLines.push(line);
else
goodLines.push(line);
$("#r1").val(goodLines.join("n"));
$("#r2").val(badLines.join("n"));#s background: lightblue;
#r1 background: lightgreen;
#r2 background: red;<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="7" id="s" >
line ok
line nok kaka
ok row
baka this row
sakalento row
lento 'saka' badddd
</textarea>
<textarea rows="5" id="r1"></textarea>
<textarea rows="5" id="r2"></textarea>edited Nov 15 '18 at 18:04
answered Nov 15 '18 at 16:07
SergeSerge
3,31234394
3,31234394
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
add a comment |
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
Thank you, I myself began to look for a solution. It could have been done like this: document.getElementById ("prex"). InnerHTML.split (" n"); And then process it as a regular array. And I tried to come up with something very complicated.
– lebokywer
Nov 15 '18 at 17:45
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
run the code snippet and see the output, is that you wanted?
– Serge
Nov 15 '18 at 17:47
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
observe, the "kakaSomething" would not be taken in consideration, only "kaka" as entire word
– Serge
Nov 15 '18 at 17:49
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
Why this script not support any unicode or symbols such @@?
– lebokywer
Nov 15 '18 at 18:50
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
what script? what do you mean "not support"
– Serge
Nov 16 '18 at 9:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322663%2fidentifying-strings-that-contain-keywords%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is that this what are you searching for? codepen.io/serhio/pen/YRVMWK?editors=1010
– Serge
Nov 15 '18 at 15:35
I do not know how to select text with multiple delimiters and keywords. The example works with only one pair of dividers. And I need to process all that have a tag span. As I understand you just copied my code.
– lebokywer
Nov 15 '18 at 15:49
I fixed your code a little. what do you what to extract from "hello<br>1<br>2<br>yes", having "<br>" as delimiter?
– Serge
Nov 15 '18 at 15:57
Script work 1 time for 1 keyword. I need him to be able to process all the lines with spreaders. What do they contain span tag.
– lebokywer
Nov 15 '18 at 16:13
please give an example as input, and the output you want to be more clear to us what do you want.
– Serge
Nov 15 '18 at 16:17