Ali Tor
Ali Tor

Reputation: 2945

Why doesn't Regex returns all matches that fits pattern?

I need to extract filename in those formats like filename=FileName.Extension.
I have a Regex pattern, but when I test it it returns only 1 match instead 2.
What is wrong with this pattern?

pattern:

(?<=filename=).+\..+

test string::

idman636build5.exe?b=1&filename=idman636build5.exeidman636build5.exe?b=1&filename=idman636build5.exe

Expected matches:

The regex engine is .NET's default engine. I don't know the name of it.

See the result in Regex101

Upvotes: 0

Views: 71

Answers (2)

Dave Cluderay
Dave Cluderay

Reputation: 7426

I guess you want to consider the end of the filename to be the ? or & character. Changing the expression to match anything up to either character:

(?<=filename=)[^&?]+

Upvotes: 1

Eraklon
Eraklon

Reputation: 4288

The last .+ will match the second one since it says match anything. (?<=filename=).+\..+\n this way only the first is matched for example.

Upvotes: 0

Related Questions