user3138879
user3138879

Reputation: 183

Regular expression to match text after 3 character from string

I have a string like

January
February
March

I want a regex which matches only uary(January), ruary(February) and ch(march) i.e string after 3 character

I have tried this [a-zA-Z]{1,3}(.*?)$ Its working but giving match in group. I don't want in group. I want pure match

Upvotes: 3

Views: 4237

Answers (3)

bjfletcher
bjfletcher

Reputation: 11508

You can use:

\b\w{3}

\b is word boundary, then 3 alphanumerics (plus any underscore).

Here'a a demo: https://regex101.com/r/dX8eC7/1

Upvotes: 0

Avinash Raj
Avinash Raj

Reputation: 174696

Use lookbehind.

(?<=^[a-zA-Z]{3}).*

or \K

^[a-zA-Z]{3}\K.*

Upvotes: 1

Andris Leduskrasts
Andris Leduskrasts

Reputation: 1230

Your regex is actually the kind of thing that would be used for this ($ aside), and the "uary" and what not would be called with $1.

(?<=[a-zA-Z]{3}).*(?=\s|$) will do in non-javascript languages, without any capture groups.

https://regex101.com/r/iV0tR3/1

Upvotes: 2

Related Questions