Javascript 在typescript中拆分字符串的最佳方法是什么

Javascript 在typescript中拆分字符串的最佳方法是什么,javascript,arrays,string,typescript,split,Javascript,Arrays,String,Typescript,Split,我有字符串输入,比如 输入 text:string=today午餐200酒店名称 输出 主题:今天午餐 售价:200 标签:hotelname 我的解决办法是 text: string = "today lunch 200 #hotelname" tag: string; price: string; subject: string; this.text.forEach(x => { if(this.reg.test(x)){ this.tag

我有字符串输入,比如

输入 text:string=today午餐200酒店名称

输出 主题:今天午餐 售价:200 标签:hotelname

我的解决办法是

text: string = "today lunch 200 #hotelname"
  tag: string;
  price: string;
  subject: string;

 this.text.forEach(x => {
      if(this.reg.test(x)){
         this.tag= x;
      }else if(parseInt(x)){
          this.price = x;
      }
      else{
        this.subject= x;
      }
    });
 console.log(this.subject, this.tag, this.price);
但问题是我的解决方案并不能满足所有的测试用例,有没有更好的解决方案使用typescript或javascript

测试用例

字符串不能有两个no 例1:今天午餐200酒店200 例2:200食物2 0 1意大利面 以开头的文本被视为标记,并且不能在一个文本中有多个标记 一串 如果绳子像xyz酒店100中国人的食物 输出:主题:xyz酒店的食物 价格:100 标签:chinies 使用匹配:

让string=today午餐200 hotelname;
console.logstring.match/*\s+\d+\s+.*/Stack Overflow不是代码编写服务,请分享您自己尝试过的内容。在你提出要求之前,你应该做一些研究。最快的方法是自己写,而不是等待一个慷慨的傻瓜为你写,因为你不知道你需要等待多久