문제

I am using VBA to filter records in an MS Access Database I first need to clean the data in a particular column

An example item in this column would be XXXZZZSTYS1234NCYORGxxxASD

What i would like to do is if the string contains STY then remove subsequent characters until you reach COYORGxxx or NCYORGxxx or CNYORGxxx and then remove any characters after the ORGxxx if they exist

So in the example above it would be cleaned to XXXZZZSTYNCYORGxxx

It doesn't have to be VBA, I use notepad++ to test it

도움이 되었습니까?

해결책

You could try the following regex:

(.*?STY).*?((COY|NCY|CNY)ORGxxx).*

And replace it with:

$1$2

Where:

  • $1 represents all characters until the first "STY"
  • $2 represents COYORGxxx or NCYORGxxx or CNYORGxxx

다른 팁

There you go.

(.*STY).*((CO|NC|CN)YORGxxx).*
  • (.*STY) will catch every string of characters up to STY

  • .* will skip characters until next catch

  • ((CO|NC|CN)YORGxxx) will catch any string starting with CO, NC or CN followed by YORGxxx

  • and the last .* is just here to ensure the match (not necessary in this specific example)

You then only need to replace with $1$2, $n representing the n-th catch of the regex.

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