【发布时间】:2018-05-19 18:40:10
【问题描述】:
如何从字符串中提取第一个特殊字符(仅允许 # 和 .)?
例如:
svg#hello 将返回 #
-hello-world#testing 将返回 #
-hello-world.testing 将返回 .
.test 将返回 .
等等?
【问题讨论】:
-
str.match(/[#.]/) -
请参阅 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 了解有关 adeneo 答案的说明。
标签: javascript