Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想找到以文本和“-”字符开头的字符串,找到这个:
2030- OR 2232- OR 2544- etc
我试过了:
/(2030-|2232-|2544-|33-)/i
这不适用于“-”或其他字符,需要帮助
/^.*?-/
是最一般的构造
这将匹配从字符串开头到第一个“-”的任何字符串
Try this general regex:
regex
/(\d+\-)/i
explanation
\d Matches any decimal digit.
\d
这个 reg 应该适合你:
/^(?:2030|2232|2544|33)-$/
确保锚点^和$这样放置。
^
$