0

I have a long long regexp, like this (it's example):

/111|112|113|...|998|999/

How can I make it multiline to edit it with ease? Something like that:

/
111
|112
|113
...
|998
|999
/
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142

2 Answers2

2

You can create regexp using constructor:

new RegExp('/'
+ '111'
+ '|112'
+ '|113'
+ '...'
+ '|998'
+ '|999'
+ '/');

From ES6 you can also use backticks to write multiline strings:

new RegExp(`/
111
|112
|113
...
|998
|999
/`);
madox2
  • 49,493
  • 17
  • 99
  • 99
1
var str = "/111|112|113|...|998|999/";
var splitArr = str.split("|");

function divide(){
   var s= "";       
   for(var i=0;i<splitArr.length;i++){
    var item = splitArr[i] + "\n";
    s +=  item;
   }
    return s
}

console.log(divide());
Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29