使用jQuery替换通配符文本 [英] Replacing wildcard text using jquery

查看:99
本文介绍了使用jQuery替换通配符文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含公司信息(地址,电话等)的数据库

I have a database that contains company information (address, telephone etc)

在某些电话号码上,将使用国际代码:+44(0)123 12345

On some of the telephone numbers it will have an international code: +44 (0) 123 12345

其中(0)取决于国家/地区的数字将不同.

where the (0) will be different numbers depending on country.

我需要剥离(0)

我有以下代码:

var el = $('#contactdetails');
el.html(el.html().replace("(0)", "-"));

可在(0)上使用-但是我该如何对通配符进行操作

which works on (0) - but how do I do this for wildcards

推荐答案

使用正则表达式.

var el = $('#contactdetails');
el.html(el.html().replace(/\([0-9]\)/, "-"));

如果有一个以上的单数位,则将*用于上一个表达式的任意出现次数.

If there is more than a singe digit, then use the * for any number of occurrences of the previous expression.

el.html(el.html().replace(/\([0-9]*\)/, "-"));

此处的实时示例

这篇关于使用jQuery替换通配符文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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