[Solved] How to remove a string date exist in a list of Strings in dart?
Question
Asked by Faris S on June 22, 2022 (source).
I have a list of strings and one if it's items looks like this '19-06-2022 12:37' ..
How can i remove any pattern like this if it exist in the list using Dart language ?
Answer
Question answered by Harish S (source).
You can remove any pattern from string by using String class method replaceAll
. If you want to remove any pattern then you need to use RegExp like below example.
There are also other method like replaceFirst
, replaceRange
for more details Read Here
String testSt = "12-02-2022 16:23";
String myPattern = "^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2}) [012]{0,1}[0-9]:[0-6][0-9]";
testSt.replaceAll(new RegExp(myPattern),"");
SHARE: