iOS Phonegap正则表达式替换 [英] iOS Phonegap regex replace
问题描述
我可能只是在这里做一些显而易见的事,但我可以得到这个代码在Chrome控制台中工作,但是当我在我的phonegap应用程序中运行它只是不做任何事情。
I might just be doing something obvious and dumb here, but I can get this code to work in the Chrome console, but when I run it in my phonegap app it just doesn't do anything.
我将一些来自网站API的邮件提取到phonegap随播应用程序。问题是消息中有链接到网站。我想使用regex将href更改为onClick,所以它适用于我的应用程序。
I'm pulling in some messages from an website API to a phonegap companion app. The problem is the messages have links in them to the website. I want to use regex to change the href to an onClick so it works with my app.
如果我在Chrome中运行这个代码很好:
If I run this code in Chrome it's fine:
avar = '<a href="view.php?id=63">Click here to view details</a>';
bvar = avar.replace(
/<a href="view\.php\?id=([0-9])*">/gi,
'<a onClick="navigator.notification.alert(\'ok\')">AAA'
);
我将正则表达式剥离回来了,但仍然失败了
I stripped the regex right back to this, and it still fails
bvar = avar.replace(
/<a href="/gi,
'TEST'
);
再次,它适用于Chrome而不是Phonegap应用程序。任何想法?
Again that works in Chrome and not the Phonegap app. Any ideas?
推荐答案
如果它似乎有问题,尝试在你的正则表达式的括号:
if it seems to have issues with the ", try putting brackets around what you are regex-ing:
bvar = avar.replace(
/(<a href=")/gi,
'TEST'
);
同样,使用console.log,只需检查正则表达式是否在js中正确注册。
also, using the console.log, just check that the regex is getting registered in js correctly.
var rgxtest = /(<a href=")/gi
console.log(rgxtest);
这篇关于iOS Phonegap正则表达式替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!