开发者

RegExp Escape Problem?

开发者 https://www.devze.com 2023-01-11 02:36 出处:网络
I need some RegExp help for a Flex 3 website. I\'m trying to find this: px;\'</img> And replace it with:

I need some RegExp help for a Flex 3 website. I'm trying to find this:

px;'</img>

And replace it with:

px;'></img>
开发者_开发知识库

I've tried:

var tester: String = " blah height: 0px;'<\img>blah";                           

var pattern1:RegExp = /px;'<\/img>/g;
tester = tester.replace(pattern1, "px;'></img>");

I think that the problem is with escaping the / in the img tag, but I'm not sure.

Any suggestions?

Thank you.

-Laxmidi


Your regex looks right. Your test string, on other hand, has a backslash instead of a forward slash:

var tester: String = " blah height: 0px;'<\img>blah";                           


No need for regexp:

tester = tester.replace("px;'</img>", "px;'></img>");

As a rule of thumb, don't use regex unless what you are looking for is variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号