Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _4_ReplaceTag
- {
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main(string[] args)
- {
- StringBuilder ads = new StringBuilder();
- string readLine = Console.ReadLine();
- string output = string.Empty;
- while (readLine != "end")
- {
- ads.Append(readLine);
- readLine = Console.ReadLine();
- }
- string pattern = @"(<ahref=|<a\Whref=|<a\nhref=).+("">).+(<\/a>)";
- Regex regex = new Regex(pattern);
- string replacment1 = "[URL href=";
- string replacment2 = "\"]";
- string replacmennt3 = "[/URL]";
- readLine = ads.ToString();
- if (regex.IsMatch(readLine))
- {
- string match1 = regex.Match(readLine).Groups[1].ToString();
- output = Regex.Replace(readLine, match1, replacment1);
- string match2 = regex.Match(readLine).Groups[2].ToString();
- output = Regex.Replace(output, match2, replacment2);
- string match3 = regex.Match(readLine).Groups[3].ToString();
- output = Regex.Replace(output, match3, replacmennt3);
- }
- Console.WriteLine(output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement