How to comment multiple lines when a regexpression uses */?

I want to comment out multiple lines, but when I use /* */ it conflicts because of the */ use in a regular expression. Solution?

Example code:

		let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
		let chewieRegex = /Aa*/; 
		let resultQuote = chewieQuote.match(chewieRegex);
		console.log(resultQuote); // ["Aaaaaaaaaaaaaaaa"]


You will have to change the let chewieRegex = /Aa*/; line to:
let chewieRegex = /Aa*//*;

Or just use // on each line.

Appreciate it, Randell. Kinda crazy they don’t have an option to add more *s like


to combat that. Cheers.

If you select several lines the keyboard shortcut Ctrl-K Ctrl-C will comment them all as an inline comment.

This can be undone with Ctrl-K Ctrl-U.

Thank you this helps a lot!

1 Like

In most text editors, you can toggle commenting/uncommenting by pressing Ctrl+/. I think the Ctrl+K shortcuts are Visual Studio–specific.

That may be - but they have been working for me in the default FCC environment all the past week since I joined, in a vanilla Chrome browser.

(P.S. - Don’t tell Bill).

Ooh, interesting. I guess it implements shortcuts from all over the place, then. :grin:

1 Like