using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(.*)%%sql\s+-o\s+(\w+)\s+(\-([n|q|r])(\s+[a-z0-9]+)?)?\s?(\\n)?\s?select\s+(.+)\s+from([\w\s\.\-'\""=]+)(\\n)?(.*)$";
string input = @"\n//something \nimport com.adobe.platform.dataset.DataSetOptions\n\nvar df1 = spark.read.format(\""com.adobe.platform.dataset\"")\n .option(DataSetOptions.orgId, \""310C6D375BA5248F0A494212@AdobeOrg\"")\n .option(DataSetOptions.batchId, \""dbe154d3-197a-4e6c-80f8-9b7025eea2b9\"")\n .load(\""5e68141134492718af974844\"")\n\ndf1.printSchema()\ndf1.show()\n// this should be changed\n%%sql -o df -n 30 \nselect * from sparkdf where sparkdf.x='something'\n// # and this line not\n \n\n//import com.adobe.platform.dataset.DataSetOptions\n\nvar userToken = spark.sparkContext.getConf.getOption(\""spark.yarn.appMasterEnv.USER_TOKEN\"").get\nvar serviceToken = spark.sparkContext.getConf.getOption(\""spark.yarn.appMasterEnv.SERVICE_TOKEN\"").get\nvar serviceApiKey = spark.sparkContext.getConf.getOption(\""spark.yarn.appMasterEnv.SERVICE_API_KEY\"").get\n\ndf1.write.format(\""com.adobe.platform.dataset\"")\n .option(DataSetOptions.orgId, \""310C6D375BA5248F0A494212@AdobeOrg\"")\n .option(DataSetOptions.userToken, userToken)\n .option(DataSetOptions.serviceToken, serviceToken)\n .option(DataSetOptions.serviceApiKey, serviceApiKey)\n .save(\""5e68141134492718af974844\"")\n// \n\n//end
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx