0

I am trying to use javascript or angularjs to make a table header titles return the words in parentheses on their own line. Therefore for instance

abcdefg (x yz)

, should make the title look like this:

abcdefg 
(x yz)

I tried to split on parentheses but this returns every word separated and then i would need to reconstruct the string into 2 parts.

uniXVanXcel
  • 807
  • 1
  • 10
  • 25

1 Answers1

0

This is doing the job:

var test = [
    "abcdefg x yz",
    "abcdefg (x yz)",
];
console.log(test.map(function (a) {
  return a.replace(/(?=\()/, '<br>');
}));

Where (?=\() is a positive lookahead, a zero-length assertion that makes sure we have an open parenthesis. The replacement is made just before this parenthesis.

Toto
  • 89,455
  • 62
  • 89
  • 125