Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a text in a textarea and I read it out using the .value attribute.

(我在textarea中有一个文本,并使用.value属性将其读出。)

Now I would like to remove all linebreaks (the character that is produced when you press Enter ) from my text now using .replace with a regular expression, but how do I indicate a linebreak in a regex?

(现在,我想使用正则表达式.replace从我的文本中删除所有换行符(按Enter时产生的字符),但是如何在正则表达式中指示换行符?)

If that is not possible, is there another way?

(如果那不可能,还有另一种方法吗?)

  ask by Wingblade translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
512 views
Welcome To Ask or Share your Answers For Others

1 Answer

How you'd find a line break varies between operating system encodings.

(换行符的查找方式因操作系统编码而异。)

Windows would be \r\n , but Linux just uses \n and Apple uses \r .

(Windows将是\r\n ,但是Linux仅使用\n而Apple使用\r 。)

I found this in JavaScript line breaks :

(我在JavaScript换行符中发现了这一点:)

someText = someText.replace(/(
|
|
)/gm, "");

That should remove all kinds of line breaks.

(那应该删除所有换行符。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...