开发者

Regex error when handling with tags

I am trying to convert this:

[img,src=http://www.ANYTHINGHERE.com/image.png,width=55px,height=105px]<br />

To this:

<img src="http://www.ANYTHINGHERE.com/image.png" width=55px height=105px>

(without spaces)

I am trying with this regex:

/(\[img[| |,|]?[(s开发者_如何学运维rc=(.*)?)|(width=(.*)?)|(height=(.*)?)|,]*)(\])/<br />

But it doesn't find the tag


The regex without escaping:

[([a-z]+?),([a-z]+?)=([^,]+),([a-z]+?)=([^,]+),([a-z]+?)=([^,]+)]

and replace in pseudocode:

<$1 $2="$3" $4="$5" $6="$7">


I might add there are lots of resources to test regex, like this Regex Tester, which gives you real time feedback to how your regex is matching.


You'll need to escape a lot of those characters.

EDIT: Now looking at your actual regex, the problem is the character class in the middle. You realize character classes are only for alternations of individual characters, right?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜