Using QString I can remove any character from string, but what would be QRegExp to remove ALL non alphanumeric characters from that string. Currently I have written a function that will remove each character one by one, but I would like to know if i can do the same thing only in one step.

Here is my function

Qt Code:
  1. QString clean(QString str)
  2. {
  3. str.remove("\"");
  4. str.remove("\\");
  5. str.remove(".");
  6. str.remove(",");
  7. str.remove("?");
  8. str.remove("!");
  9. str.remove("'");
  10. str.remove("`");
  11. str.remove("-");
  12. str.remove("_");
  13. str.remove("—");
  14. str.remove("@");
  15. str.remove("#");
  16. str.remove("$");
  17. str.remove("%");
  18. str.remove("^");
  19. str.remove("&");
  20. str.remove("*");
  21. str.remove("(");
  22. str.remove(")");
  23. str.remove("{");
  24. str.remove("}");
  25. str.remove("[");
  26. str.remove("]");
  27. str.remove("|");
  28. str.remove(";");
  29. str.remove(":");
  30. str.remove("/");
  31. str.remove(">");
  32. str.remove("<");
  33. str.remove("~");
  34. str.remove("=");
  35. str.remove("+");
  36. str.remove(str.fromUtf8("«"));
  37. str.remove(str.fromUtf8("»"));
  38. str = str.trimmed();
  39. return str;
  40. }
To copy to clipboard, switch view to plain text mode