What I am trying to do is to select every line of javascript code except for the comments (just the comments /** to */ with or without spaces in the beginnig) and replace with the word (code). I need it with a RegEx and replace javascript function.
For example
Input
/**
* Source Code
*/
/**
* Places given shatter objects images into the specified dom element
*
* @param {object} shatter - Shatter object
* @param {object} domElement - The dom element to append images to
*/
function placeShatter (shatter, domElement) {
// adjustment to center image on screen
var adjustment = (window.innerWidth / 2) * image.width / 2;
for (var i = 0; i < shatter.images.length; i++) {
placeImageAbsolute(shatter.images[i].image,
domElement,
shatter.images[i].x,
shatter.images[i].y,
adjustment,
YLOC);
}
}
Output
/**
* Source Code
*/
/**
* Places given shatter objects images into the specified dom element
*
* @param {object} shatter - Shatter object
* @param {object} domElement - The dom element to append images to
*/
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
(code)
The RegEx has to work with this code:
<!DOCTYPE html>
<html>
<body>
<p>Source Code</p>
<textarea rows="50" cols="150" id="input"></textarea>
<p>Click the button to perfom a global replacement and display the matches.</p><button onclick="myFunction()">Try it</button>
</br>
<textarea rows="50" cols="150" id="output"></textarea>
<script>
function myFunction() {
var not_comments = document.getElementById("input").value.replace(RegEX,'(code)');
document.getElementById("output").value = not_comments;
}
</script>
</body>
</html>
. But I need to do it with RegEx.
– Papaya Labs Jun 08 '15 at 23:07