SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 21-04-2021 16:37:07

StephanB
Member
Registered: 21-11-2018
Posts: 39

Using a regex on a Substitute Rules

Using a regex to select everything before a character:

The values we receiving from the Client on the Server tag is not always the same :
Exsamples:

<Server>BDHPAM01 Source:BJHVMH01</Server>
<Server>BDHPAM02_Source:BJHVMH01</Server>
<Server>BDHPAMSource:BJHVMH01</Server>

I only want the "BJHVMH01" value.

This is how I was able to get the correct values by using a regex.

I used a regex "^(.*?)\:" to select everything before a character ":" and Replacing it with nothing giving me the value of "TJHVMH01".

<sxi:Field name="mServer">
   <sxi:Rules>
       <sxi:Substitute>
            <!-- regex to select everything before ":" -->
            <sxi:Find>^(.*?)\:</sxi:Find>
            <sxi:Replace></sxi:Replace>
        </sxi:Substitute>
   </sxi:Rules>
   <sxi:OutputField>Server</sxi:OutputField>
</sxi:Field>

There is a couple ways this can be done .... 
Please add to this post how you will do it.

Offline

#2 21-04-2021 19:10:46

SeanR
Administrator
Registered: 20-11-2018
Posts: 148

Re: Using a regex on a Substitute Rules

Is there a reason you didn't simply split on the ":" and put element [1] into an output field?

Offline

#3 22-04-2021 08:05:20

StephanB
Member
Registered: 21-11-2018
Posts: 39

Re: Using a regex on a Substitute Rules

Yes, when we get the following two values and do a split on the "\" and ":" we get Index 0.
"RFSSQL21\SQL1QBS" -----> RFSSQL21 = Index 0
"BDHPAM02Source:BJHVMH01" -----> BDHPAM02Source = Index 0, 
I need the "BJHVMH01" value by doing a substitute find replace with the regex "^(.*?)\:" will give the correct value "BJHVMH01"

Example :

        <sxi:Field name="mServer">
          <sxi:Rules>
            <sxi:Split>
              <sxi:Delimiter>\\</sxi:Delimiter>
              <sxi:OutputFields>
                <sxi:OutputField index="0">TmpServer</sxi:OutputField>
              </sxi:OutputFields>
            </sxi:Split>
            <sxi:TrimAllBlanks/>
          </sxi:Rules>
          <sxi:OutputField>Omit</sxi:OutputField>
        </sxi:Field>
        <sxi:Field name="TmpServer">
          <sxi:Rules>
            <sxi:Substitute>
              <sxi:Find>^(.*?)\:</sxi:Find>
              <sxi:Replace></sxi:Replace>
            </sxi:Substitute>
          </sxi:Rules>
          <sxi:OutputField>Server</sxi:OutputField>
        </sxi:Field>

Offline

#4 22-04-2021 09:04:22

SeanR
Administrator
Registered: 20-11-2018
Posts: 148

Re: Using a regex on a Substitute Rules

This still doesn't explain why you are not doing a second split.

E.g.

<sxi:Field name="mServer">
          <sxi:Rules>
            <sxi:Split>
              <sxi:Delimiter>\\</sxi:Delimiter>
              <sxi:OutputFields>
                <sxi:OutputField index="0">TmpServer</sxi:OutputField>
              </sxi:OutputFields>
            </sxi:Split>
            <sxi:TrimAllBlanks/>
          </sxi:Rules>
          <sxi:OutputField>Omit</sxi:OutputField>
        </sxi:Field>
        <sxi:Field name="TmpServer">
          <sxi:Rules>
            <sxi:Split>
              <sxi:Delimiter>:</sxi:Delimiter>
              <sxi:OutputFields>
                <sxi:OutputField index="1">Server</sxi:OutputField>
              </sxi:OutputFields>
            </sxi:Split>
          </sxi:Rules>
          <sxi:OutputField>Omit</sxi:OutputField>
        </sxi:Field>

If you want to use regex perhaps provide the full source field example and we can look at one step to get the value you need.

Offline

Board footer

Powered by FluxBB