如何将此字符串与正则表达式匹配

时间:2023-01-14 14:15:04

So I have this string: (a url)

所以我有这个字符串:(一个网址)

example.html/#playYouTubeVideo=id[lBs8jPDPveg]&width[160]&height[90]

I want to match id, width and height. And the value in [ ]

我想匹配id,width和height。和[]中的值

I came up with this:

我想出了这个:

[=|&](\w+)(?!\[)(.+?)(?=\])

But the match for group #1: i, widt and heigh
And the match for group #2: d[lBs8jPDPveg, h[160 and t[90

但是组#1的匹配:i,widt和heigh以及组#2的匹配:d [lBs8jPDPveg,h [160和t [90]

So the error is that the last letter in the name and [ is in group #2
Anyone got an idea how to fix it?

所以错误是名称中的最后一个字母和[在#2组中的任何人都知道如何修复它?

1 个解决方案

#1


3  

Why don't you do:

你为什么不这样做:

[=&|](\w+)\[([^\]]+)\]

Group 1 will have id, width, height, group 2 will have what's in the [].

组1将具有id,width,height,组2将具有[]中的内容。

(Do you actually want the | in that preceding bit?)

(你真的想要在前面的那个位吗?)

#1


3  

Why don't you do:

你为什么不这样做:

[=&|](\w+)\[([^\]]+)\]

Group 1 will have id, width, height, group 2 will have what's in the [].

组1将具有id,width,height,组2将具有[]中的内容。

(Do you actually want the | in that preceding bit?)

(你真的想要在前面的那个位吗?)