javascript - 需要有关 Javascript 正则表达式的帮助

标签 javascript regex

该框应允许:

  • 大小写字母(不区分大小写)
  • 数字 0 到 9
  • Angular 色,! # $ % & ' * + -/= ? ^ _ ` { | } ~
  • 字符“.”前提是它不是第一个或最后一个字符

最佳答案

尝试

^(?!\.)(?!.*\.$)[\w.!#$%&'*+\/=?^`{|}~-]*$

说明:

^         # Anchor the match at the start of the string
(?!\.)    # Assert that the first characters isn't a dot
(?!.*\.$) # Assert that the last characters isn't a dot
[\w.!#$%&'*+\/=?^`{|}~-]*   # Match any number of allowed characters
$         # Anchor the match at the end of the string

关于javascript - 需要有关 Javascript 正则表达式的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4848623/

相关文章:

javascript - 如何在单击时切换按钮内的类?

javascript - Dynamicpage div 在加载新内容后不久闪烁

ios - 从字符串中删除多个换行符/回车符

java - 根据某些规则分割字符串

javascript - 'Object.assign' 在更深层次上改变状态

javascript - CSS:为什么我有一个 100% 高度的滚动条?

javascript - 将数据标签添加到没有设置列的谷歌图表

regex - 使用replaceMatchesInString循环

c# - 代码审查 : CLR RegexSubstring

c# - 获取模式之后没有类或 ID 的文本