I am parsing a log file with 3 variations of a line and I'm trying to build a regex that matches and groups all variations.
Here are the line variations:
StatementId: [12345], UserId: 8756
StatementId: 12345, UserId: 8756
StatementId: [12345,6789], UserId: 8756
The current expression I have matches all cases, except #3.
I am expecting 2 groups. Using the lines above, the first group would be either 12345 or 12345,6789 The second group would simply be 8756
The problem I'm having is with line variation #3. The closing bracket ] being included in the first matching group.
Thus for line #3 the first group result is:
12345,6789]
I'm using this site for testing:
Here is my regex:
(?:StatementId: \[?)(.*)(?:\]?, .*UserId: )([0-9]*)
What am I doing wrong?
EDIT:
I've attempted the suggested non-greedy solution(s) in several variations but that doesn't appear to solve the problem.
The expression variations I've tried will work on a single line variation, but not on all 3.
SOLUTION:
sln in the comments had 2 suggested solutions, both of which work.