Home > Net >  NetSuite Saved Search: REGEXP_SUBSTR Pattern troubles
NetSuite Saved Search: REGEXP_SUBSTR Pattern troubles

Time:02-19

I am trying to break down a string that looks like this:

|5~13~3.750~159.75~66.563~P20~~~~Bundle A~~|

Here is a second example for reference:

|106~10~0~120~1060.000~~~~~~~|

Here is a third example of a static sized item:

|3~~~~~~~~~~~5:12|

Example 4:

|3~23~5~281~70.250~upper r~~~~~~|
|8~22~6~270~180.000~center~~~~~~|
|16~22~1~265~353.333~center~~~~~~|

Sometimes there are multiple lines in the same string.

I am not super familiar with setting up patterns for regexp_substr and would love some assistance with this!

The string will always have '|' at the beginning and end and 11 '~'s used to separate the numeric/text values which I am hoping to obtain. Also some of the numeric characters have decimals while others do not. If it helps the values are separated like so:

|Quantity~ Feet~ Inch~ Unit inches~ Total feet~ Piece mark~ Punch Pattern~ Notch~ Punch~ Bundling~ Radius~ Pitch|

As you can see, if there isn't something specified it shows as blank, but it may have them in another string, its rare for all of the values to have data.

For this specific case I believe regexp_substr will be my best option but if someone has another suggestion I'd be happy to give it a shot!

This is the formula(Text) I was able to come up with so far:

REGEXP_SUBSTR({custbody_msm_cut_list},'[[:alnum:]. ] |$',1,1)

This allows me to pull all the matches held in the strings, but if some fields are excluded it makes presenting the correct data difficult.

CodePudding user response:

TRIM(REGEXP_SUBSTR({custbody_msm_cut_list}, '^\|(([^~]*)~){1}',1,1,'i',2))

From the start of the string, match the pipe character |, then match anything except a tilde ~, then match the tilde. Repeat N times {1}. Return the last of these repeats.

You can control how many tildes are processed by the integer in the braces {1}

EG:

TRIM(REGEXP_SUBSTR('|Quantity~ Feet~ Inch~ Unit inches~ Total feet~ Piece mark~ Punch Pattern~ Notch~ Punch~ Bundling~ Radius~ Pitch|', '^\|(([^~]*)~){1}',1,1,'i',2))

returns "Quantity"

TRIM(REGEXP_SUBSTR('|Quantity~ Feet~ Inch~~~ Piece mark~ Punch Pattern~ Notch~ Punch~ Bundling~ Radius~ Pitch|', '^\|(([^~]*)~){7}',1,1,'i',2))

returns "Punch Pattern"

The final value Pitch is a slightly special case as it is not followed by a tilde:

TRIM(REGEXP_SUBSTR('|~~~~~~~~~~ Radius~ Pitch|', '^\|(([^~]*)~){11}([^\|]*)',1,1,'i',3))

Adapted and improved from https://stackoverflow.com/a/70264782/7885772

  • Related