ButtressCoral
ButtressCoral

Reputation: 113

Regex "match up to" (in two cases)

I have the following regex expression which will capture the start of a quote tag and the author in various cases.

I cannot get it to match up to link= OR pid= (note the space before each of those).

At the moment, I think what is happening is the expression is matching indiviual letters, instead of the strings above.

\[(quote)\]?\s*(?:author)?=?(.[^link=|pid=]+[\w]*).*?\]

An example of the string I'm testing the regex on. I'm trying to capture two things: "quote" (which becomes my $1), and then the username (in various cases, which becomes my $2).

The substitution is [$1=$2].

I'm trying to stop the expression at a closing square bracket, so I don't have to deal with the quote tag contents, or the final close tag. The expression only deals with the opening quote tag and attributes.

[quote='User Name' pid='1082654' dateline='1411779439']Test[/quote]

With the regex expression above, it would match:

[quote='User Name' pid]Test[/quote]

When it should match everything above, except for the "pid". Here is a more complete example: http://regex101.com/r/iK2nO2/1

How can I more clearly define where the capture group should stop? I'm using this with PHP so I think the PCRE flavor.

Upvotes: 2

Views: 140

Answers (1)

vks
vks

Reputation: 67968

\[(quote)\]?\s*(?:author)?=?((?:(?!\s+link|\s+pid).)+).*?\]

Try this.See demo.

http://regex101.com/r/iK2nO2/3

Upvotes: 1

Related Questions