Delete line starting with a word in Javascript using regex

前端 未结 1 1403
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 13:32

I have few lines on text.

Random 14637547548546546546sadas3463427
Random 1463754754854654654sadsa63463427
Macroflex 1463754754854654sada65

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 13:51

    You have to replace to the end of the line:

    var myRegex = data.replace(/^Macroflex.*$/m, '');
    

    Note that you have to specify the m flag to let ^ and $ work with newlines.

    If you want to remove the newline after the line, you can match it:

    var myRegex = data.replace(/^Macroflex.*\n?/m, '');
    

    This works since . does not match newlines.

    0 讨论(0)
提交回复
热议问题