正则表达式[任何数字] [英] Regular expression [Any number]

查看:85
本文介绍了正则表达式[任何数字]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试javascript字符串中的"[any number]".我怎么匹配呢?

I need to test for "[any number]" in a string in javascript. how would i match it?

哦,"["和]"也需要匹配.

Oh, "[" and "]" also need to be matched.

所以像"[1]"或"[12345]"这样的字符串都是匹配项.

so string like "[1]" or "[12345]" is a match.

不匹配:"[23432"或"1]"

Non match: "[23432" or "1]"

例如:

$('.form .section .parent').find('input.text').each(function(index){
      $(this).attr("name", $(this).attr("name").replace("[current]", "['"+index+"']"));
});

我需要将输入字段名称:"items [0] .firstname"替换为"items [1] .firstname" 谢谢

I need to replace input fields name: "items[0].firstname" to "items[1].firstname" thanks

推荐答案

更新:您的更新问题

variable.match(/\[[0-9]+\]/);

尝试一下:

variable.match(/[0-9]+/);    // for unsigned integers
variable.match(/[-0-9]+/);   // for signed integers
variable.match(/[-.0-9]+/);  // for signed float numbers

希望这会有所帮助!

这篇关于正则表达式[任何数字]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆