Removed regex list instead using first parameter for regex pattern

This commit is contained in:
Jaex 2022-01-31 13:01:36 +03:00
parent 1b0262ce4f
commit 57972d07cb
3 changed files with 18 additions and 13 deletions

View file

@ -269,7 +269,6 @@ public void ParseResponse(UploadResult result, ResponseInfo responseInfo, Custom
{
FileName = input.FileName,
ResponseInfo = responseInfo,
RegexList = RegexList,
URLEncode = true
};

View file

@ -36,7 +36,6 @@ public class CustomUploaderSyntaxParser : ShareXSyntaxParser
public string FileName { get; set; }
public string Input { get; set; }
public ResponseInfo ResponseInfo { get; set; }
public List<string> RegexList { get; set; }
public bool URLEncode { get; set; } // Only URL encodes file name and input
public bool JSONEncode { get; set; }
public bool XMLEncode { get; set; }

View file

@ -35,26 +35,33 @@ public override string Call(CustomUploaderSyntaxParser parser, string[] paramete
{
if (parameters.Length > 0)
{
string regexIndex = parameters[0];
string pattern = parameters[0];
if (!string.IsNullOrEmpty(regexIndex) && int.TryParse(regexIndex, out int regexIndexNumber))
if (!string.IsNullOrEmpty(pattern))
{
string pattern = parser.RegexList[regexIndexNumber - 1];
Match match = Regex.Match(parser.ResponseInfo.ResponseText, pattern);
if (parameters.Length > 1)
if (match.Success)
{
string regexGroup = parameters[1];
if (!string.IsNullOrEmpty(regexGroup) && int.TryParse(regexGroup, out int regexGroupNumber))
if (parameters.Length > 1)
{
return match.Groups[regexGroupNumber].Value;
string group = parameters[1];
if (!string.IsNullOrEmpty(group))
{
if (int.TryParse(group, out int groupNumber))
{
return match.Groups[groupNumber].Value;
}
else
{
return match.Groups[group].Value;
}
}
}
return match.Groups[regexGroup].Value;
return match.Value;
}
return match.Value;
}
}