首页 > 解决方案 > 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

标签: regex

解决方案


听起来你正在寻找前瞻:

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

推荐阅读