Girish Jain
Girish Jain

Reputation: 645

Regex for skipping certain number of characters from end of a string

I need a regex to return input string minus certain number of characters from end. Input string will be series of alphanumeric characters (minus space).

For example, when input string is ABC123456789 I want regex to return all but last 4 characters.

Please don't ask why I need a regex for this trivial requirement.

Upvotes: 1

Views: 40

Answers (1)

anubhava
anubhava

Reputation: 785376

Not sure why substring won't work for you but if regex is must to use then use:

^(.*?)\w{4}$

And use captured group #1.

RegEx Demo

Upvotes: 1

Related Questions