0

i need to separate the special character【0003】from the text 一方、テオフィリ

<div class="PAR">
        【0003】一方、テオフィリン系薬剤においては、安全域が狭く使用面の制約を
 </div> 

if(dataText.match(/【[0123456789]+】/)){

            let textSplit = dataText.split(/【[0123456789]】/);

            console.log("find text ", textSplit);
          }

The output need to be an array with [ 【0003】, 一方、テオフィリ ];

The problem it is on the split

corsaro
  • 731
  • 1
  • 9
  • 24
  • 1
    Assuming there will only be one `】`, you can split on that using something like this: [Javascript and regex: split string and keep the separator](https://stackoverflow.com/a/25221523/1650337) – DBS Aug 12 '22 at 14:38

2 Answers2

0

You can use the split method directly:

const str = '0003】一方、テオフィリン系薬剤においては、安全域が狭く使用面の制約を';

const words = str.split('】');
console.log(words[0]);
console.log(words[1]);
Armando Guarino
  • 1,120
  • 1
  • 5
  • 16
0

Check "splitting and keeping the separators". https://www.wisdomgeek.com/development/web-development/javascript/javascript-split-string-and-keep-the-separators/

const re = /(【[0123456789]+】)/;
const s = "【0003】一方、テオフィリン系薬剤においては、安全域が狭く使用面の制約を";
const out = s.split(re);
console.log(out);
James
  • 20,957
  • 5
  • 26
  • 41