BIS Tech
BIS Tech

Reputation: 19514

how to remove after dot letters on dart using Regular expression?

    String abc = 'abc.jpg';
    //or
    String abc = 'abc.png';
    //or
    String abc = 'abc.xxxx';

How to remove .png or .jpg or .xxxx?

I tried this way. But not working

print(abc.replaceAll(RegExp("\.\$"),''));

Upvotes: 1

Views: 1743

Answers (5)

Jabaseelan S
Jabaseelan S

Reputation: 49

 str.toStringAsFixed(0);

simply add this to your string it removes the string after the dot(.).

Upvotes: 0

Jahanvi Kariya
Jahanvi Kariya

Reputation: 397

try this:-

print(abc.split(RegExp(r"(\.+)"))[0]);

Hope it will work

Upvotes: 3

Marc Ma
Marc Ma

Reputation: 338

With regular expression:

https://stackoverflow.com/a/624877/8619512

Try this:

(.+?)(.[^.]*$|$) This will:

Capture filenames that start with a dot (e.g. ".logs" is a file named ".logs", not a file extension), which is common in Unix. Gets everything but the last dot: "foo.bar.jpeg" gets you "foo.bar". Handles files with no dot: "secret-letter" gets you "secret-letter".

Upvotes: 1

Anil Chauhan
Anil Chauhan

Reputation: 714

Try with :

print(abc.replaceAll('.', ''));

or 

with Regx: 

print(abc.replaceAll(RegExp('[^a-z0-9_]+'),''));

Upvotes: 3

Marc Ma
Marc Ma

Reputation: 338

Use

filename = abc.split(".")[0]

It's that simple :)

Upvotes: 3

Related Questions