The following is a sample of a file I’m editing in vim
cutAct = new QAction( tr( "Cut" ) );
cutAct->setShortcut( QKeySequence::Cut );
cutAct->setStatusTip( tr( "Cut the current selection" ) );
connect( cutAct, SIGNAL( triggered() ), this, SLOT( cut() ) );
I’m trying to use sed from vim’s command pane to convert all instances of cutAct to actionCut, with the intention being to test my expression before using it to carry out similar conversions on other elements of my code that have a <someString>Act name, so that they all instead follow a action<SomeString> naming convention. So basically:
- Start with cutAct
- Cut it in half before the ‘Act’ part, so it is cut and Act
- Upper-case the ‘c’ in cut so I have ‘Cut’ and ‘Act’
- Drop the ‘Act’ and replace it with ‘action’ prepended to the front of ‘Cut’.
This is an example of what I’m after
actionCut = new QAction( tr( "Cut" ) );
actionCut->setShortcut( QKeySequence::Cut );
actionCut->setStatusTip( tr( "Cut the current selection" ) );
connect( actionCut, SIGNAL( triggered() ), this, SLOT( cut() ) )
and I’m trying to use the following command to do it
s_[a-z]\(.*\)Act_action\u\1_g
but what I’m getting out is this
actionUtAct = new Qion( tr( "Cu&t" ), this );
actionUt->setShortcut( QKeySequence::Cut );
actionUt->setStatusTip( tr( "Cut the current selection" ) );
actionOnnect( cut, SIGNAL( triggered() ), diaryEditor, SLOT( cut() ) );
This is my first attempt at any serious use of regular expressions, and I would have believed that my expression would have returned every string starting with a lower case alpha character and anding in ‘Act’ before removing the Act from the end, making the first character upper-case and prepending ‘action’ to the front, but that clearly isn’t what’s happening.
Can someone please tell me how to modify my expression to achieve what I’m after?
In your example:
c*utAct = new QAct*ion( tr( “Cut” ) );
group 1 in the regular expression matches the part in italic. The initial
[a-z]is outside the parentheses, and regular expressions are greedy, so.*followed byActwill match the last “Act” in the string, not the first.Try this:
s_\([a-z]\w*\)Act_action\u\1_g