HarshvardhanSharma
HarshvardhanSharma

Reputation: 786

regexp: match everything beginning from second dot including dot

I want to match everything beginning from second ., including .

Regexp: /(?<=\d\.\d+)\..*/g. Playground regex101

It does not work for strings 1232..233232.

Upvotes: 0

Views: 65

Answers (2)

3limin4t0r
3limin4t0r

Reputation: 21160

When reading your question literally.

I want to match everything beginning from second ., including .

This would do the trick:

[.][^.]*([.].*)

Leaving the resulting answer in group 1. Keep in mind that [^.] also matches newline characters, if you don't want this add \n to the character negation class.

Upvotes: 0

Nils K&#228;hler
Nils K&#228;hler

Reputation: 3001

Update

as @WiktorStribiżew points out the regex don't test for 1212.2e1.121212 os this might be a better solution.

/(?<=^[^.]*\.[^.]*)\..*/ since it will also test for this

old answer.

You can do this regex101, this will begin including from the second . including it.

Regexp: /(?<=\d?\.\d*)\..*/g

You need to use * (include 0 to x elements of this character) instead of + (include 1 to x of this character)

I have added a ? after your first \d to handle the case if it starts with a . and not a digit.

Upvotes: 1

Related Questions