regex


1. Email Validation

#include <regex>

bool IsValidEmail(const std::string& email) {
  std::regex pattern(
      "^\\s*[a-zA-Z0-9_\\.\\+\\-]+@[a-zA-Z0-9\\.\\-]+\.[a-zA-Z0-9]{2,}\\s*$");
  return std::regex_match(email, pattern);
}

2. Phone Number Validation

#include <regex>

bool IsValidPhoneNumber(const std::string& phone) {
  std::regex pattern(
      "^(\\+\\d{1,2}\\s?)?((\\d{3}\\s?)|(\\d{2,3}-?)|\\d{2,3})\\s?(\\d{3}-?)"
      "?\\s?(\\d{4}|\\d{3}-?)\\s?(\\d{4}|\\d{3}-?)\\s*$");
  return std::regex_match(phone, pattern);
}

3. Password Strength Validation

#include <regex>

bool IsStrongPassword(const std::string& password) {
  std::regex pattern("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*#?&])[A-Za-z\\d@$!%*#?&]{8,}$");
  return std::regex_match(password, pattern);
}

4. URL Validation

5. IP Address Validation

6. HTML Tag Removal

7. Date Extraction from Text

8. Find and Replace Text

9. Split String by Delimiter

10. Check for White Space Only

11. Find and Match Whole Words

12. Match Multiple Patterns

13. Match Using Negative Lookahead

14. Match Using Positive Lookahead

15. Match Using Grouping

16. Replace Using Grouping

17. Tokenize Using Regex

18. Find and Replace Using Iterators

19. Check for Palindrome

20. Check for SSN

21. Check for Credit Card Number

22. Check for Bitcoin Address

23. Check for MAC Address

24. Check for IPv6 Address

25. Check for File Extension

26. Remove Leading and Trailing Whitespace

27. Check for Valid Time

28. Check for Strong Password