I am trying to remove everything between two words with brackets. The words are: {start}
and {end}
(function ($) {
$(document).ready(function(){
$('.well.save').on('mouseleave touchend', function(){
// alert('mouseleave touchend');
var $editor = $(".markItUpEditor");
var curValue = $editor.val();
//alert(curValue);
// check
var confCheck = curValue.includes("{start}");
//alert(confCheck);
if (confCheck == true) {
var myStr = $editor.val();
var subStr = myStr.match("{start}(.*){end}");
alert(subStr[1]);
//$editor.val(curValue);
}
});
})(jQuery);
The code above returns null.
I am getting the content from a textarea. This textarea has a section with text added on mouseleave. This section starts with the word {start}
and ends with the word {end}
now I want to remove everything between those two words and the words as well so that on the next mouse leave I can re-add updated information.
Jquery version is from native Joomla 3. And the textarea contains the following:
There is some text in the message!
[confidential]
{start}
Site URL:
Site Username:
Site Password:
FTP URL:
FTP Username:
FTP Password:
Optional Information:
{end}
[/confidential]```
Once you have the string, the code is as follows - Your final edit gave me the hint that you have a multiline string. Here is the code to fix it
https://regex101.com/r/4MYLO3/3
Remove between - MULTILINE
var re = /{start}([\S\s]*?){end}/gm
var str = $(".editor").val()
var newStr = str.replace(re,"");
console.log(newStr);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="editor" rows="10">There is some text in the message!
[confidential]
{start}
Site URL:
Site Username:
Site Password:
FTP URL:
FTP Username:
FTP Password:
Optional Information:
{end}
[/confidential]</textarea>
Copy from between
var re = /{start}([\S\s]*?){end}/gm
var str = $(".editor").val()
var newStr = str.match(re);
console.log(newStr);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="editor" rows="10">There is some text in the message!
[confidential]
{start}
Site URL:
Site Username:
Site Password:
FTP URL:
FTP Username:
FTP Password:
Optional Information:
{end}
[/confidential]</textarea>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments