Domanda

I tried quite a few things but Im stuck with my regex whenever meets the criteria 2 consecutive times. In this case it just considers it as one expressions instead of 2.

\[ame\=[^\.]+(.+)youtube\.(.+)v\=([^\]\&\"]+)[\]\'\"\&](.+)\[\/ame\]

E.g.

[ame="http://www.youtube.com/watch?v=brfr5CD2qqY"][B][COLOR=yellow]http://www.youtube.com/watch?v=brfrx5D2qqY[/COLOR][/B][/ame][/U] [B][COLOR=yellow]or[/COLOR][/B] [B][COLOR=yellow]B[/COLOR][/B] [ame="http://www.youtube.com/watch?v=M9ak3rKIBAU"][B][COLOR=yellow]http://www.youtube.com/watch?v=M9a3arKIBAU[/COLOR][/B][/ame] [B][COLOR=yellow]or[/COLOR][/B] [B][COLOR=yellow]C[/COLOR][/B] [ame="http://www.youtube.com/watch?v=7vh--3pyq5U"][COLOR=yellow]http://www.youtube.com/watch?v=7vh--3pyq5U[/COLOR][/ame]

In that case, this regex would instead of matching all 3 options, it takes it as one.

Any ideas how to make an expression that would say match the first "[/ame]"?

È stato utile?

Soluzione

The problem is the use of .+ - they are "greedy", meaning they will consume as much input as possible and still match.

Change them to reluctant quantifiers: .+?, which won't skip forward over the end of the first match to match the end if the last match.

Altri suggerimenti

I'm not sure what your objective is (you haven't made that clear yet)

But this will match and capture out the youtube URL for you, ensuring you only match each single instance between [ame= and [/ame]

/\[ame=["'](.*?)["'](.*?)\/ame\]/i

Here's a working example, and a great sandbox to play around in: http://regex101.com/r/jR4lK2

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top