Question #10   Submitted by Answiki on 04/29/2020 at 05:59:50 PM UTC

In JavaScript, how to check whether a string contains a line break?

Answer   Submitted by Answiki on 04/29/2020 at 06:11:22 PM UTC

The following checks whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

4 events in history
Question by Answiki 04/29/2020 at 06:12:38 PM
In JavaScript, how to check whether a string contains a carriage return?
Answer by Answiki on 04/29/2020 at 06:11:22 PM

The following checks whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

Answer by Answiki on 04/29/2020 at 06:01:30 PM

The following check whether a string contains a line break (\n o r \r) :

var str = "abc \n def";
if (/\r|\n/.exec(str)) {
	// Do something, the string contains a line break

}

Question by Answiki 04/29/2020 at 05:59:50 PM
In JavaScript, how to check whether a string contains a line break?
# ID Query URL Count

Icons proudly provided by Friconix.