OGH
OGH

Reputation: 550

regex for anything after a word except last character

I need a regex for the last word after the word typedef, except for the last character. I know that ([^typedef]*)$ would give me the last word after typedef, but that would include the last character.

For example if I had the line type long long integer;, I want a regex that would give me integer, not integer;. If this helps, the last character will always be a semicolon.

Upvotes: 2

Views: 1297

Answers (2)

anubhava
anubhava

Reputation: 784998

This is the regex that should work for you:

^typedef.*?\s(\w+)\s*;

Last word is available in matching group #1.

Live Demo: http://www.rubular.com/r/Bzko9WIITw

Upvotes: 3

d g
d g

Reputation: 1604

Add a period after your parenthesis to match 1 character but not capture it: ([^typedef]*).$

Upvotes: 0

Related Questions