-1

tested this how to remove brackets character in string (java) but it doens't worked in Dart. Any tipps to remove ( ) in a String?

My Code:

  String num = (85);
  num.replaceAll("\\p{P}", "");

Result should be: 85

FantaMagier
  • 162
  • 3
  • 9

1 Answers1

5

You need to use a compiled RegExp object with unicode: true argument:

String num = "(85)";
print(num.replaceAll(new RegExp(r"\p{P}", unicode: true), ""));

This outputs 85 as \p{P} is now treated as a punctuation proper matching Unicode property class regex.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563