D
D
Dubolom Unicellular2020-05-08 01:15:01
JavaScript
Dubolom Unicellular, 2020-05-08 01:15:01

How to find all characters after a dot?

Goodnight. I need to remove all characters after the dot, I tried like this:

text.replace(/\.*\*/, "");
// И вот так
text.replace(/\.*\./, "");

But it doesn't work, it doesn't even return anything to the console!
How to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
LissaAlbatross, 2020-05-08
@duboloms

var text = 'test.test1111';
console.log(text.split('.')[0]);

D
Dmitry Belyaev, 2020-05-08
@bingo347

Perhaps it's time to write an article on Habr about the harmfulness of RegExp. Your misunderstanding of what happens in the simplest regular season only proves it. And I will answer you, like many others before you, that you do not need RegExp, because it is very expensive, both in calculation and in support.

I need to remove all characters after the dot
const p = text.indexOf('.');
const result = p === -1 ? text : text.slice(0, p);
console.log(result);

tried like this:text.replace(/\[.][A-Z]/, "");
This regular expression will find the first dot immediately followed by a capital Latin letter and cut out only this particular combination, which does not correspond to the question at all.

F
felony13twelve, 2020-05-08
@felony13twelve

Yuzai split

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question