[英]Remove all characters before “-” on each line of multiline textarea text
I am getting some text from a multiline textarea, each line is separated by a line break: 我从多行文本区域中获取了一些文本,每行由换行符分隔:
1 - test1
2 - test2
3 - test3
4 - test4
How can I remove on each line all text before the -
, so the text will look like: 如何删除
-
之前的所有文本,所以文本看起来像:
test1
test2
test3
test4
You could look for no dashes and a dash and replace with an empty string for multiline data. 您可以查找没有破折号和破折号,并用空字符串替换多行数据。
var string = ' 1 - test1\\n 2 - test2\\n 3 - test3\\n 4 - test4', result = string.replace(/^[^-]+-/gm, ''); console.log(result);
You can do it using split and splice. 您可以使用split和splice进行操作。
const mytext = ' 1 - test1'; const arr = mytext.split('-'); const splice = arr.splice(1,1 ,''); const final = splice.toString(); console.log(final);
this could be solved with a regular expression. 这可以用正则表达式解决。 Try to put down your string to check if it is possible.
尝试放下字符串以检查是否可行。
here is the good website for it: https://regex101.com/ 这是一个不错的网站: https : //regex101.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.