w3resource

C# Sharp Regular Expression : Exercises, Practice, Solution

C# Sharp Regular Expression [9 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a C# Sharp program to check whether a given string is a valid Hex code or not. Return true if this string is a valid code otherwise false.
Sample Data:
("#CD5C5C") -> True
("#f08080") -> True
("#E9967A") -> True
("#EFFA07A") -> False
Click me to see the solution

2. Write a C# Sharp program to calculate the average word length in a given string. Round the average length up to two decimal places.
Sample Data:
("CPP Exercises." -> 6
("C# syntax is highly expressive, yet it is also simple and easy to learn.") -> 4
(“C# is an elegant and type-safe object-oriented language") -> 5.62
Click me to see the solution

3. Write a C# Sharp program to check whether a given string of characters can be transformed into a palindrome. Return true otherwise false.
Sample Data:
("amamd") -> True
("pamamd") -> False
("ferre") -> True
Click me to see the solution

4. Write a C# Sharp program to validate a password of length 7 to 16 characters with the following guidelines:
• Length between 7 and 16 characters.
• At least one lowercase letter (a-z).
• At least one uppercase letter (A-Z).
• At least one digit (0-9).
• Supported special characters: ! @ # $ % ^ & * ( ) + = _ - { } [ ] : ; " ' ? < > , .
Sample Data:
("Suuu$21g@") -> True
("W#1g@") -> False
("a&&g@") -> False
("sdsd723#$Amid") -> True
("sdsd723#$Amidkiouy") -> False
Click me to see the solution

5. Write a C# Sharp program to check whether two given strings contain the same character pattern.
Sample Data:
("AACC", "PPRR") -> True
("FFGG", "ADAD") -> False
Click me to see the solution

6. Write a C# Sharp program to check for repeated occurrences of words in a given string.
Sample Data:
("C# C# syntax is highly expressive, yet it is is also simple and easy to to learn learn.") -> 3 matches found
("Red Green Green Black Black Green.") -> 2 matches found
Click me to see the solution

7. Write a C# Sharp program to check whether a given string represents a currency value or has the correct format to represent a currency value.
Click me to see the solution

8. Write a C# Sharp program to remove special characters from given text. Return the updated string which allows alphanumeric characters, spaces, underscores _ and dashes - .
Sample Data:
("AA@%^&CC") -> "AACC"
("Python") -> "Python"
("w3resource.com") -> "w3resourcecom"
Click me to see the solution

9. Write a C# Sharp program to locate the word “C#” in a given string. If the word "C#" is found, return “C# document found.” otherwise return “Sorry no C# document!”.
Sample Data:
("C# Exercises") -> "C# document found."
("Python Exercises") -> "Sorry no C# document!"
("Tutorial on c#") -> "C# document found."
Click me to see the solution

C# Sharp Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/csharp-exercises/re/index.php