html5?属性用于匹配正则,需要正则表达式帮助html 5模式属性的字符串的特殊匹配(Need regular expression help for special matching of str...

需要正则表达式帮助html 5模式属性的字符串的特殊匹配(Need regular expression help for special matching of string for html 5 pattern attribute)

我一直试图找到一个正则表达式来满足我需要的要求,到目前为止还没有运气。

我目前正在尝试以下正则表达式以允许这些电子邮件规则:

@@test@address.com

test@address.com

test@address.com@

var email = "@@test@test.com"; //needs to also regular email or 2 @ symbols in front or trailing

var patt = new RegExp("^\@{0,2}\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*@{0,2}​‌‌​​$");

var res = patt.test(email);

浏览器显示错误,但声明“\”是启动代码块的无效字符。

I have been trying to find a regular expression to match requirements I need, and have had no luck so far.

I am currently trying the following regex to allow for these email rules:

@@test@address.com

test@address.com

test@address.com@

var email = "@@test@test.com"; //needs to also regular email or 2 @ symbols in front or trailing

var patt = new RegExp("^\@{0,2}\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*@{0,2}​‌‌​​$");

var res = patt.test(email);

The browser displays an error though stating that "\" is an invalid character for the starting of a code block.

原文:https://stackoverflow.com/questions/39414967

更新时间:2020-01-21 13:38

最满意答案

/^@{0,2}[\w-._]+@[\w-]+\.\w+@{0,2}$/

此表达式匹配您的所有三个示例。 让我知道这是否有效,或者是否还有其他规则要遵循。

/^@{0,2}[\w-._]+@[\w-]+\.\w+@{0,2}$/

This expression matches all three of your examples. Let me know if this works, or if there are any other rules to follow.

相关问答

这是完成这项工作的一种方式: $strs = array('^hello world^', 'my ^hello world^');

foreach($strs as $str) {

echo $str, preg_match('/^\^.*\^$/', $str) ? "\tmatch\n" : "\tdoesn't match\n";

}

输出: ^hello world^ match

my ^hello world^ doesn't match

Here is

...

你需要再一次逃脱\同时将它放在分隔符内" var regexp = "^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";

要么 var regexp = /^(([^<>()[\]\\.,;:\s@\"]+(

...

我相信你的意思是用+表示你正在使用的一个或多个地方? 表示0或1。 I believe you mean to use + to indicate one or more of where you're using ? to indicate 0 or 1 of.

尝试这个 Pattern pattern = Pattern.compile("\\$@([^\\$@]+|$)");

CharSequence tag = "any tag$@ws2-role$@ws1-role";

Matcher matcher = pattern.matcher(tag);

while (matcher.find()) {

System.out.println(matcher.group(1));

}

产量 ws2-role

ws1-role

Try this

...

你可以利用负向前瞻。 例如, >>> re.findall(r'-(?!aa|bb)([^-]+)', string)

['a', 'bc', 'def', 'ghij']

-比赛- (?!aa|bb)负向前瞻,检查-是否-后面没有aa或bb ([^-]+)匹配除了以外的ony或更多字符- 编辑 上面的正则表达式与那些以aa或bb开头的正则表达式不匹配,例如-aabc- 。 为了照顾我们可以添加-像前面这样的, >>> re.findall(r'-(?!aa-|bb-)([^-]+)', str

...

你需要执行一个非贪婪的匹配:/(< /(

$doc->loadHTML($html);

$tables = $doc->getElementsByTagName('table');

foreach($tables as $table) {

...

大卫,原因(]*>)>是你有一个小错字。 你看,该表达式尝试匹配两个结束> :仔细查看结束>)> 。 例如,它会匹配>但不会 要匹配开头跨度,请确保只有一个> 。 有了所有关于使用正则表达式来匹配html的免责声明,这个正则表达式将会: ]*>

如果您有时期望SPAN ,请确保使其不区分大小写。 只有你有时间:一个额外的蓬勃发展 在评论中,@ David Ehrmann指出上面的正则表达式将匹配

...

/^@{0,2}[\w-._]+@[\w-]+\.\w+@{0,2}$/

此表达式匹配您的所有三个示例。 让我知道这是否有效,或者是否还有其他规则要遵循。 /^@{0,2}[\w-._]+@[\w-]+\.\w+@{0,2}$/

This expression matches all three of your examples. Let me know if this works, or if there are any other rules to follow.

我重新格式化了你的xml片段,以便它更具可读性。 可以清楚地看到xml无效(我们已经知道,因为XmlDocument无法解析它)。 显然,attributetwo的内容应该是ab&\"'< ,但是没有一个xml解析器可以理解,因为”&“(应该是” & “)和最后一个”\n

\t\n

\t\taa\n

\t\t

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值