Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 zadacha ///////////////////////////////////////////////////////
- string text = Console.ReadLine();
- string pattern = @"(<a href=)(.*(?=>))(>)(.*(?=<))(</a>)";
- string replace = @"[URL href=$2]$4[/URL]";
- var replaced = Regex.Replace(text, pattern, replace);
- Console.WriteLine(replaced);
- 2 zadacha ///////////////////////////////////////////////////////
- string text = Console.ReadLine();
- string pattern = @"(<a href=)(.*(?=>))(>)(.*(?=<))(</a>)";
- string replace = @"[URL href=$2]$4[/URL]";
- var replaced = Regex.Replace(text, pattern, replace);
- Console.WriteLine(replaced);
- 3 zadacha ///////////////////////////////////////////////////////
- string text = Console.ReadLine();
- string patternMeil = @"([a-zA-Z0-9_\-][a-zA-Z0-9_\-\.]{0,49})" +
- @"@(([a-zA-Z0-9][a-zA-Z0-9\-]{0,49}\.)+[a-zA-Z]{2,4})";
- Regex regexMail = new Regex(patternMeil);
- MatchCollection matches = regexMail.Matches(text);
- // Console.WriteLine("Found {0} matches", matches.Count);
- foreach (Match name in matches)
- {
- Console.WriteLine(name.Groups[0]);
- }
- 4 zadacha ///////////////////////////////////////////////////////
- string word = Console.ReadLine();
- string text = Console.ReadLine();
- string pattern = string.Format(@"(?<=\s|^)(.*?\b{0}\b.*?(?=\!|\.|\?)[?.!])", word);
- Regex regexSentence = new Regex(pattern);
- MatchCollection matches = regexSentence.Matches(text);
- Console.WriteLine("Found {0} matches", matches.Count);
- foreach (Match sentence in matches)
- {
- Console.WriteLine(sentence.Groups[0]);
- }
- 5 zadacha domashno ot java basiv 21 septemvri user names
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- string pattern = @"\b[a-zA-Z]\w{2,24}\b";
- Regex users = new Regex(pattern);
- MatchCollection matches = users.Matches(text);
- List<string> valid = new List<string>();
- int first = 0;
- int second = 1;
- int bestSum = int.MinValue;
- int sum = 0;
- int biggestSum = 0;
- int pos = 0;
- for (int i = 0; i < matches.Count - 1; i++)
- {
- int currSum = matches[i].Length + matches[i + 1].Length;
- if (currSum > biggestSum)
- {
- biggestSum = currSum;
- pos = i;
- }
- }
- Console.WriteLine(matches[pos]);
- Console.WriteLine(matches[pos + 1]);
- }
- }
- }
- moq zadacha za 2 nai golemi stringa kato stoinost /////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- string pattern = @"\b[a-zA-Z]\w{2,24}\b";
- Regex users = new Regex(pattern);
- MatchCollection matches = users.Matches(text);
- List<string> values = new List<string>();
- List<int> keys = new List<int>();
- foreach (var match in matches)
- {
- if (char.IsLetter(match.ToString().First()))
- {
- values.Add(match.ToString());
- }
- }
- int sum = 0;
- string hui = "";
- for (int i = 0; i < matches.Count; i++)
- {
- sum = 0;
- hui = Convert.ToString(matches[i]);
- for (int j = 0; j < hui.Length; j++)
- {
- char charek = hui[j];
- sum += charek;
- }
- keys.Add(sum);
- }
- var dict = keys.Zip(values, (k, v) => new { Key = k, Value = v })
- .ToDictionary(x => x.Key, x => x.Value);
- List<KeyValuePair<int, string>> myList = dict.ToList();
- myList.Sort(
- delegate(KeyValuePair<int, string> firstPair,
- KeyValuePair<int, string> nextPair)
- {
- return firstPair.Key.CompareTo(nextPair.Key);
- }
- );
- myList.Reverse();
- var kkk = 0;
- foreach (var dr in myList)
- {
- kkk++;
- if (kkk >= 11) break;
- Console.WriteLine("{0,10} = {1,3}",dr.Value, dr.Key);
- }
- }
- }
- }
- 6 zadacha //////////////////////////////////////////////////////
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class ExtractHyperlinks
- {
- static void Main(string[] args)
- {
- string inputLine;
- StringBuilder sb = new StringBuilder();
- while (!((inputLine = Console.ReadLine()) == "END"))
- {
- sb.Append(inputLine);
- }
- string text = sb.ToString();
- // Nakov @"<\s*a\s[^>]*?\bhref\s*=\s*('(?<url>[^']*)'|""(?<url>[^""]*)""|(?<url>\S*))[^>]*>(?<linktext>(.|\s)*?)<\s*/a\s*>";
- // Innos @"(?<=<a\s+(?:[^>]+\s+)?href\s*=\s*)(?:""([^""]*)""|'([^']*)'|([^\s>]+))(?=[^>]*>)";
- string pattern = @"<a\s+(?:[^>]+\s+)?href\s*=\s*(?:'(?<url>[^']*)'|""(?<url>[^""]*)""|(?<url>[^\s>]+))[^>]*>";
- Regex users = new Regex(pattern);
- MatchCollection matches = users.Matches(text);
- //Console.WriteLine("Found {0} matches", matches.Count);
- foreach (Match hyperlink in matches)
- {
- Console.WriteLine(hyperlink.Groups["url"]);
- }
- }
- }
- 7 zadacha ////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- class QueryMess
- {
- static void Main(string[] args)
- {
- string text;
- string patternRepl = @"\s{2,}";
- Regex regexRepl = new Regex(patternRepl);
- string pattern = @"([^=&]+)=([^&=]+)";
- Regex regex = new Regex(pattern);
- MatchCollection matches;
- var query = new Dictionary<string, List<string>>();
- while (!((text = Console.ReadLine()) == "END"))
- {
- text = text.Replace("%20", " ").Replace("+", " ").Replace("?", "&");
- text = regexRepl.Replace(text, " ");
- matches = regex.Matches(text);
- foreach (Match match in matches)
- {
- string field = match.Groups[1].ToString().Trim();
- string value = match.Groups[2].ToString().Trim();
- if (!query.ContainsKey(field))
- {
- query.Add(field, new List<string>());
- }
- query[field].Add(value);
- }
- foreach (string field in query.Keys)
- {
- Console.Write("{0}=[{1}]", field, string.Join(", ", query[field]));
- }
- Console.WriteLine();
- query.Clear();
- }
- }
- }
- 8 zadacha /////////////////////////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _08.UseYourChainsBuddy
- {
- class UseYourChainsBuddy
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex rgx = new Regex(@"<p>(.*?)<\/p>");
- Match match = rgx.Match(input);
- StringBuilder sb = new StringBuilder();
- while (match != Match.Empty)
- {
- string text = Regex.Replace(match.Groups[1].Value, @"[^a-z0-9]+", " ");
- text = Regex.Replace(text, @"\s+", " ");
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i] >= 97 && text[i] <= 109)
- {
- sb.Append((char)(text[i] + 13));
- }
- else if (text[i] >= 110 && text[i] <= 122)
- {
- sb.Append((char)(text[i] - 13));
- }
- else
- {
- sb.Append(text[i]);
- }
- }
- match = match.NextMatch();
- }
- Console.WriteLine(sb.ToString());
- }
- }
- }
- 9 zadacha ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _09.SemanticHTML
- {
- class SemanticHTML
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex rgxOpen = new Regex("(\\s*)<(div).*((id|class)\\s*=\\s*\"(?<hoi>.*?)\").*(?=>)");
- Regex rgxClose = new Regex("(\\s*)<\\/div>\\s.*?(?<kur>\\w+)\\s*-->");
- List<string> result = new List<string>();
- string semantic;
- Match match;
- while (input != "END")
- {
- if (input.Contains("<div"))
- {
- match = rgxOpen.Match(input);
- semantic = match.Value;
- semantic = semantic.Replace(match.Groups[2].Value, match.Groups["hoi"].Value);
- semantic = semantic.Replace(match.Groups[3].Value, " ");
- semantic = Regex.Replace(semantic.Trim(), "\\s+", " ");
- semantic = match.Groups[1].Value + semantic + ">";
- result.Add(semantic);
- }
- else if (input.Contains("</div"))
- {
- match = rgxClose.Match(input);
- semantic = match.Groups[1].Value + "</" + match.Groups["kur"].Value + ">";
- result.Add(semantic);
- }
- else
- {
- result.Add(input);
- }
- input = Console.ReadLine();
- }
- foreach (string s in result)
- {
- Console.WriteLine(s);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement