简体   繁体   English

将字符串拆分为多个以特殊字符开头和结尾的子字符串

[英]Split string into multiple substrings starting and ending with special character

I have a string like我有一个像

"i have #newCar and the #noTime in #Days"

and I want to extract words starting with # :我想提取以#开头的单词:

a = "#newCar","#noTime',"#Days"

How can I do this?我怎样才能做到这一点?

You can use a regex for this purpose您可以为此使用正则表达式

const s = "i have #newCar and the #noTime in #Days"
const regex = /#[a-zA-Z]+\b/g

console.log(s.match(regex)) // ["#newCar", "#noTime", "#Days"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以特殊字符序列将一个字符串分成一对子字符串 - Separate a string into a pair of substrings at a special character sequence 使用字符串中的开始和结束词以及javascript中的子字符串索引查找子字符串? - Find substring using starting and ending word in a string and substrings indexes in javascript? javascript - 通过指定起始和结束字符来拆分字符串 - javascript - split string by specifying starting and ending characters 以字符开头并以数字结尾的字符串的模式匹配 - Pattern matching for a string starting with character and ending with digit 获取起始字符和结束字符之间的字符串 - get the string between starting character(s) and ending character(s) 验证一个或多个不以特殊字符开头和结尾的字符字符串 - Validating a one or more char string not starting and ending with special characters 需要删除句子中部的特殊字符,但不删除字符串的开头和结尾 - need to remove special characters in the midle of sentence but not starting and ending of the string 将字符串拆分为以“]开头,以“ As”结尾的子字符串 - Split a string into sub-strings starting from “ ] ” ending with “As” 如何在JavaScript中按空格和特殊字符分割字符串? - How to split a string by space and special character in javascript? 将数组中的字符串拆分为子字符串 - Split string in array to substrings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM