Split string into hyphen in javascript

I want to split the next line into two using split javascript function

Original line "Medium Dimensional" - "Mega Church!" (with single quotes)

please note that inside the line

and I want to break it with a hyphen, so the result will be

[0] Average Sized 
[1] Mega Church!
+5
source share
4 answers

try the following:

"Average Sized - Mega Church!".split(/\s*\-\s*/g)

edit:

if you mean the source string INCLUDES single quotes, this should work:

"'Average Sized - Mega Church!'".replace(/^'|'$/g, "").split(/\s*\-\s*/g)

if you only meant that the string is defined with single quotes, the original will work.

+6
source
var str = "Average Sized - Mega Church!";
var arr = str.split("-");
+7
source
var str = "Average Sized - Mega Church!";
var arr = [];

arr = str.split('-');
+1

-

var arr = "'Average Sized'-'Mega Church!'".replace(/'/ig,"").split("-")
0

All Articles