0

I get the pattern.
/(?<=<TOTA>[^]+\blength=")[^"]+(?="[^]+<\/TOTA>)/g

And test on regex101.com ,it can work in ECMAScript mode.

Now I want to use pattern in Vscode search, how to convert the pattern??

Below is the examples of a file.

<TxDef encoding="EBCDIC" txAdapter="Unisys" appAdapter="pass" xmlTransformer="Unisys" transportAdapter="SystemF" targetTx="" txMapper="" delimiter="" memo="pp">
  <TITA>
      <TxBlock dataTag="" renderTag="Y" memo="" ref="SystemF-TITA-COM-AREA" />
      <TxField id="BCURCD" cname="cc" datatype="9" lengthtype="F" padchar=" " justify="" default="" length="2" lengthExpr="" scale="0" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
      <TxField id="STATUS" cname="c6" datatype="9" lengthtype="F" padchar=" " justify="" default="" length="1" lengthExpr="" scale="0" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
      <TxField id="END" cname="gg" datatype="X" lengthtype="F" padchar=" " justify="" default="" length="1" lengthExpr="" scale="0" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
    </TxBody>
    <TxTail dataTag="" renderTag="Y" memo="" ref="" />
  </TITA>
  <TOTA>
    <TxHead dataTag="" renderTag="Y" memo="" ref="" />
    <TxBody dataTag="CommMsg" renderTag="Y" memo="" ref="">
      <TxRepeat dataTag="TXREC" renderTag="Y" memo="" timesField="" timesValue="-1" name="">
        <TxBlock dataTag="Header" renderTag="N" memo="" ref="SystemF-TOTA-BASIC-TxBlock" />
        <TxSwitch dataTag="" renderTag="N" memo="" switchField="WARN">
          <TxCase dataTag="" renderTag="N" memo="" value="[default]">
            <TxRepeat dataTag="TXREC" renderTag="N" memo="" timesField="" timesValue="1" name="">
              <TxField id="CNAME" cname="ed" datatype="X" lengthtype="F" padchar=" " justify="" default="" length="80" lengthExpr="" scale="0" tagSize="0" lengthSize="0" encoding="UNISYS" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
              <TxField id="AVBAL" cname="b7" datatype="S" lengthtype="F" padchar=" " justify="" default="" length="14" lengthExpr="" scale="2" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
              <TxField id="AVG03" cname="hh" datatype="9" lengthtype="F" padchar=" " justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
              <TxField id="AVG1" cname="1m" datatype="9" lengthtype="F" padchar=" " justify="" default="" length="13" lengthExpr="" scale="2" tagSize="0" lengthSize="0" encoding="" shiftInOut="Y" invisibleChar="TrimAndPadRight" memo="" optional="N" overwrite="N" codec="" renderTag="" charFormat="" />
               </TxRepeat>
            </TxRepeat>
          </TxCase >
        </TxSwitch >
      </TxRepeat >
    </TxBody>
    <TxTail dataTag="" renderTag="Y" memo="" ref="" />
  </TOTA>
</TxDef>
Poul Bak
  • 10,450
  • 5
  • 32
  • 57
Jamie
  • 21
  • 4

1 Answers1

0

Your first problem is that VS Code currently does not understand [^]. Note: regex101.com explains that [^] "matches any character, including newline". This VS Code search SO Q/A suggests using (.|\n), which should be functionally equivalent.

(?<=<TOTA>(.|\n)+\blength=")[^"]+(?="(.|\n)+<\/TOTA>)

What happens next depends on whether you are searching withing a single file editor, or searching over multiple files. According to this GitHub issue discussion,

search in the editor uses the JS regex engine, and search across files uses ripgrep which doesn't support [variable-length lookbehind assertions]. There are a small number of differences in regex feature support, this is one of them.

So it will work when searching in a single file editor, but when searching over multiple files, VS Code will error "Regex parse error: lookbehind assertion is not fixed length"

This limitation of ripgrep is inherent to its design, and would probably require a complete redesign violating its original goals to implement it. See these closed issues on the maintainer (BurntSushi)'s repo:

starball
  • 20,030
  • 7
  • 43
  • 238