Reputation: 19
I am trying to use replace in Sublime using regular expressions but I'm stuck. I tried various combinations but don't seem to be getting there.
This is the input and my desired output:
Input: N_BBP_c_46137_n
Output : BBP
I tried combinations of:
[^BBP]+\b
\*BBP*+\g
But none of the above (and many others) don't seem to work.
Upvotes: 0
Views: 155
Reputation: 163342
To turn N_BBP_c_46137_n
into BBP
and according to the comment just want that entire long name such as N_BBP_ to be replaced by only BBP* you might also use a capture group to keep BBP.
\bN_(BBP)_\S*
\bN_
Match N preceded by a word boundary(BBP)
Capture group 1, match BBP
(or use [A-Z]+
to match 1+ uppercase chars)_\S*
Match _
followed by 0+ times a non whitespace charIn the replacement use the first capturing group $1
Upvotes: 1
Reputation: 626835
You may use
(N_)[^_]*(_c_\d+_n)
Replace with ${1}some new value$2
.
Details
(N_)
- Group 1 ($1
or ${1}
if the next char is a digit): N_
[^_]*
- any 0 or more chars other than _
-(_c_\d+_n)
- Group 2 ($2
): _c_
, 1 or more digits and then _n
.See the regex demo.
Upvotes: 0