PRIM_REGX... does anyone have an example using it?

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

PRIM_REGX... does anyone have an example using it?

Post by Dino »

Hi Guys,

Does anyone know how to use this PRIM_REGX primitive?
Do you have an example for instance how to use the split to capture a collection of elements in a path?

https://docs.lansa.com/15/en/lansa016/C ... M_REGX.htm
https://docs.lansa.com/15/en/lansa016/C ... _Split.htm

kind regards,
dominique
Posts: 50
Joined: Mon May 29, 2017 4:16 pm
Location: St. Gallen, Switzerland

Re: PRIM_REGX... does anyone have an example using it?

Post by dominique »

Hi Dino

I didn't know this class existed. It's similar to .net split method
(https://learn.microsoft.com/en-us/dotne ... ew=net-7.0)

This example splits a semicolon delimited string to a collection. It's really useful!

regards
Dominique

Code: Select all

Mthroutine Name(Regex)
Define_Com Class(#PRIM_REGX) Name(#Regex)
Define_Com Class(#PRIM_REGX.CaptureCollection) Name(#RegexCapture) Reference(*DYNAMIC)
Define_Com Class(#PRIM_REGX.Capture) Name(#RegexCaptureItem) Reference(*DYNAMIC)

Define Field(#Pattern) Type(*STRING)
Define Field(#Input) Type(*STRING)
Define Field(#ItemCounts) Type(*INT)
Define Field(#ItemCurrent) Type(*INT)


#Pattern := "(;)"
#Input := "value1;value2;value3;value4;value5"

#Regex.split Tokens(#RegexCapture) Pattern(#Pattern) Inputstring(#Input)

#ItemCounts := #RegexCapture.ItemCount
#ItemCurrent := 0

Begin_Loop
#ItemCurrent += 1
#RegexCaptureItem <= #RegexCapture.item<#ItemCurrent>

Continue If(#RegexCaptureItem.Value *EQ ';')


Use Builtin(MESSAGE_BOX_APPEND) With_Args((("Item &1: &2").substitute( #ItemCurrent.asstring #RegexCaptureItem.Value ) + (13).aschar + (10).aschar))

If (#ItemCurrent >= #ItemCounts)
Leave
Endif
End_Loop

Use Builtin(Message_box_show)
Endroutine
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: PRIM_REGX... does anyone have an example using it?

Post by Dino »

Thank you Dominique, I can see now where was the problem.
It works fine when used in a form, or a server routine.

I was trying to use it in a web page where that seems not be possible (PRIM_REGX doesn't contain a type called PRIM_REGX).

I will call the server module to return the values. Changed it to this:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_SRVM)
Def_List Name(#list01) Fields(#std_strng) Type(*Working)

Srvroutine Name(RegexRoutine)
List_Map For(*Output) List(#list01)
Define_Com Class(#PRIM_REGX) Name(#Regex)
Define_Com Class(#PRIM_REGX.CaptureCollection) Name(#RegexCapture) Reference(*Dynamic)

Define Field(#Pattern) Type(*String)
Define Field(#Input) Type(*String)

#Pattern := "(;)"
#Input := "value1;value2;value3;value4;value5"

#Regex.Split Tokens(#RegexCapture) Pattern(#Pattern) InputString(#Input)

For Each(#RegexCaptureItem) In(#RegexCapture)
Continue If(#RegexCaptureItem.Value *EQ ';')
#STD_STRNG := #RegexCaptureItem.Value.AsNativeString
Add_Entry To_List(#list01)
Endfor
Endroutine
End_Com
Post Reply