【问题标题】:Split the string using regex [duplicate]使用正则表达式拆分字符串[重复]
【发布时间】:2015-06-10 12:52:18
【问题描述】:

我有一个像

这样的内文
<div contenteditable="true">
  hi</br>
  This is a multiple line</br>
  code
</div>

我想让它变成一行,而不是
占用空间并用逗号分隔它.. 我试过sTextbox.split(/[\s,]+/); 但它也包括新行 请建议我解决这个问题

更新 预期输出如下: hi this is a multipleline code.. 我必须计算sTextboxSplit[sTextboxSplit.length - 1],它给出sTextboxSplit = ["hi", "this", "is", "multiple","line","code" ""],,在此它将给出""作为我的最后一个索引,我的最后一个索引是code。 我想在 c# mvc 中工作。。

【问题讨论】:

  • 你的预期输出是什么?
  • 请为您的问题添加更多详细信息,显示预期输出,您能否向我们提供您已经在 J​​SFiddle 中尝试过的内容?
  • 一开始你应该知道stackoverflow.com/a/1732454/2956006
  • @Kasra 请查看我更新的问题
  • 为什么不改用sTextbox.split(/[ \t]+/);

标签: javascript c# regex asp.net-mvc


【解决方案1】:

您可以使用以下正则表达式:

>([^<]*?)<

Demo

这个正则表达式使用Negated Character Classes 匹配&gt;&lt; 之间的任何东西,&lt; 除外。

【讨论】:

  • 我的 sTextbox 值为 sTextbox = "bedrom0_1 people view↵t↵ 并且在应用你的建议后我得到了相同的答案..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
  • 2017-02-23
相关资源
最近更新 更多