BananaMonkey2412
BananaMonkey2412

Reputation: 181

Is there a way to get the beginning of a word based on the match of the end of the word?

I'm trying to create a regex that can find all words that end with "Ctrl" and get only the beginning of the word. So for "QuestionCtrl" I would only want to get "Question".

So far I've boiled it down to something like this: \b(\w*(Ctrl)\w*)\b

Upvotes: 0

Views: 29

Answers (1)

Snow
Snow

Reputation: 4097

Sounds like you're looking for lookahead:

\b\w+(?=Ctrl\b)

Upvotes: 2

Related Questions