St.Antario
St.Antario

Reputation: 27375

How to match a substring following after a string satisfying the specific pattern

Imagine, that I have the string 12.34some_text.

How can I match the substring following after the second character (4 in my case) after the . character. In that particular case the string I want to match is some_text.

For the string 56.78another_text it will be another_text and so on.

All accepted strings have the pattern \d\d\.\d\d\w*

Upvotes: 1

Views: 33

Answers (2)

Santosh
Santosh

Reputation: 2323

Since you are using java and the given pattern is \d\d\.\d\d\w* you will get some_text from 12.34some_textby using

String s="12.34some_text";
s.substring(5,s.length());

and you can compare the substring!

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

If you wish to match everything from the second character after a specific one (i.e. the dot) you can use a lookbehind, like this:

(?<=[.]\d{2})(\w*)

demo

(?<=[.]\d{2}) is a positive lookbehind that matches a dot [.] followed by two digits \d{2}.

Upvotes: 3

Related Questions