mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added input parameter support to custom uploader regex function
This commit is contained in:
parent
aa04cae425
commit
3c1dc2ac9a
1 changed files with 31 additions and 15 deletions
|
@ -30,6 +30,7 @@ namespace ShareX.UploadersLib
|
|||
// Example: {regex:(?<=href=").+(?=")}
|
||||
// Example: {regex:href="(.+)"|1}
|
||||
// Example: {regex:href="(?<url>.+)"|url}
|
||||
// Example: {regex:{response}|href="(.+)"|1}
|
||||
internal class CustomUploaderFunctionRegex : CustomUploaderFunction
|
||||
{
|
||||
public override string Name { get; } = "regex";
|
||||
|
@ -38,18 +39,34 @@ internal class CustomUploaderFunctionRegex : CustomUploaderFunction
|
|||
|
||||
public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
|
||||
{
|
||||
string pattern = parameters[0];
|
||||
string input, pattern, group = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(pattern))
|
||||
// {regex:input|pattern|group}
|
||||
if (parameters.Length > 2)
|
||||
{
|
||||
Match match = Regex.Match(parser.ResponseInfo.ResponseText, pattern);
|
||||
input = parameters[0];
|
||||
pattern = parameters[1];
|
||||
group = parameters[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
// {regex:pattern}
|
||||
input = parser.ResponseInfo.ResponseText;
|
||||
pattern = parameters[0];
|
||||
|
||||
// {regex:pattern|group}
|
||||
if (parameters.Length > 1)
|
||||
{
|
||||
group = parameters[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(pattern))
|
||||
{
|
||||
Match match = Regex.Match(input, pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (parameters.Length > 1)
|
||||
{
|
||||
string group = parameters[1];
|
||||
|
||||
if (!string.IsNullOrEmpty(group))
|
||||
{
|
||||
if (int.TryParse(group, out int groupNumber))
|
||||
|
@ -61,7 +78,6 @@ public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] pa
|
|||
return match.Groups[group].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return match.Value;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue