【问题标题】:Need help to write regex需要帮助编写正则表达式
【发布时间】:2017-12-20 11:07:09
【问题描述】:

我不会写正则表达式,所以我真的需要你的帮助来满足要求。我一直很亲密,但它总是在小事上失败。 这是我尝试过的最新正则表达式:

/^\\{2}[-\w]+\\(([^"*/:?|<>\\,;[\]+=.\x00-\x20]|\.[.\x20]*[^"*/:?|<>\\,;[\]+=.\x00-\x20])([^"*/:?|<>\\,;[\]+=\x00-\x1F]*[^"*/:?|<>\\,;[\]+=\x00-\x20])?)\\([^"*/:?|<>\\.\x00-\x20]([^"*/:?|<>\\\x00-\x1F]*[^"*/:?|<>\\.\x00-\x20])?\\)*$/

但结果是不允许我在服务器名称中添加点。

我需要这个被接受:

\\servername.withdot\alowing spaces\1.2.3.4\under_scores\andNotEndWithBackslash

我会尽我所能,

谢谢

【问题讨论】:

标签: javascript regex


【解决方案1】:

你可以试试:

^\\\\(?!\.)[\w\/\.-]+\\[a-zA-Z0-9 ]+\\(?!\.)[\d\.]+(?!\.)(\\\w+)+$

Regex Demo

const regex = /^\\\\(?!\.)[\w\/\.-]+\\[a-zA-Z0-9 ]+\\(?!\.)[\d\.]+(?!\.)(\\\w+)+$/;
const str = `\\\\servername.withdot\\alowing spaces\\1.2.3.4\\under_scores\\andNotEndWithBackslash`;
console.log(regex.test(str))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-19
    • 2012-11-30
    • 2023-03-19
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多