문제

Let's say I have the following text:

Lorem ipsum dolor sit amet, consectetur aaBaaBaaB adipiscing elit.

aaBaaB

aaB Ut in risus quis elit posuere faucibus sed vitae metus. aaBaaBaaBaaB

Fusce nec tortor in dolor aaBaaBaaB porttitor viverra. aaB

I'm trying to figure out how to perform a regular expression search and replace on this in such a way that the output is:

Lorem ipsum dolor sit amet, consectetur aaBaaB adipiscing elit.

aaB

Ut in risus quis elit posuere faucibus sed vitae metus. aaBaaBaaB

Fusce nec tortor in dolor aaBaaB porttitor viverra.

That is, to remove one "aaB" from each pattern of it. Is this actually possible, and if so, how would it be done? Specifically, I intend to do this in Sublime Text 2 as a RegEx search/replace in a file.

도움이 되었습니까?

해결책

You can use a positive lookahead:

(?=(?<w>[a-z]{2}[A-Z]{1})\s)\k<w>

You just need to make sure you have case-sensitive matching on.

example: http://regex101.com/r/sK8bG1

다른 팁

Use either the leading or trailing whitespace to remove the first or last substring. Either of these work:

(\s+)(aaB) with $1 in the Replace field

or

(aaB)(\s+) with $2 in the Replace field

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top