0

here we go

private static readonly string _regexPattern = @"[/]api[/]v[0-9].[0-9][/]Subscriber[/][0-9]{10}";

public override string GenerateRowKey(LogEvent logEvent, string suffix = null)
{
    var logResult = $"{logEvent.Properties["RequestPath"]}";

    var regex = new Regex(logResult);
    var fh = regex.IsMatch(_regexPattern);

    ---
}

logResult is "/api/v1.0/Subscriber/2727272727"

Have no idea why this doesn't work.

5
  • "Have no idea why this doesn't work" -- Well what is it supposed to do, we cant read your mind. We need a problem statement, sample input/output, etc Commented Sep 11, 2018 at 14:23
  • @DavidG for "/" in url. Like there is [api] for "api" Commented Sep 11, 2018 at 14:27
  • According to online regex tester like regexstorm.net/tester your regex works. Commented Sep 11, 2018 at 14:27
  • @maccettura regex is not match. If I had more info about what exactly isn't working I wouldn't ask for help Commented Sep 11, 2018 at 14:27
  • @hakamairi but it doesn't work in the code Commented Sep 11, 2018 at 14:28

1 Answer 1

2

Your passing the pattern/text in the wrong order, the ctor wants a pattern for later testing with IsMatch():

var regex = new Regex(_regexPattern);
var fh = regex.IsMatch(logResult);

There is also a static IsMatch() thats less to type & uses an internal cache.

Sign up to request clarification or add additional context in comments.

4 Comments

regex.IsMatch(logResult)?
THank you so much. Fully me
@hakamairi Yup, I've fixed it
You may want to anchor your pattern with ^/$ to avoid substring matches too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.