문제

I have the following code in a HTML page:

src="/images/picture1.gif"  ONMOUSEOVER="itempopup(event,'69168298'
src="/images/picture2.gif"  ONMOUSEOVER="itempopup(event,'69168223'
src="/images/picture3.gif"  ONMOUSEOVER="itempopup(event,'69168243'
src="/images/picture4.gif"  ONMOUSEOVER="itempopup(event,'69168249'
src="/images/pic1.gif"  ONMOUSEOVER="itempopup(event,'69168249'
src="/images/pictures10.gif"  ONMOUSEOVER="itempopup(event,'69168249'

and I want to build a Map with words of gifs that have picture+number -> {picture1=69168298, picture2=69168223 ...} I've tried to capture the word picture+number but I didn't found the right combination. Examples: ^(picture.)+$ , ^((picture).)+$, ^(?'picture'.)$. Thanks in advance!

도움이 되었습니까?

해결책

That is because your limiting the string using the ^$ characters. Just do it as follows:

(pic(ture)?s?\d+).*?event,'(\d+)'

And the \1 and \3 captured groups will contain the picture name and event id respectively

Demo

The regex above will also match cases in your example such as pic1 and pictures10, and even pics123

다른 팁

With something like this :

/(picture[0-9]+).*'([0-9]+)'/

you will capture "picture1" and "69168298"

/(pic.).gif.\'(\d+)/gi could work possibly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top