StrRegexSplit and StrRegexList - Forum

Forum Navigation
You need to log in to create posts and topics.

StrRegexSplit and StrRegexList

I do not understand the use of delimiter and the result for the 2 functions. Whichever delimiter I choose, I get the same result

SetVar "[T1]" " 8 85 89 55 77 9 40 5 57 37"

StrRegexSplit "[0-9]/+gm" "[T1]" ";" "[T11]" I expected lt an array of numbers, but the result is " 8 85 89 55 77 9 40 5 57 37"

StrRegexList "[0-9]/+gm" "[T2]" ";" "[T21]" I expected a list delimited with ; but I have no result

SetVar "[T1]" " 8 85 89 55 77 9 40 5 57 37"
StrRegexSplit "\d+" "[T1]" ";" "[T11]"
StrRegexList "\s+" "[T2]" ";" "[T21]"

Regular expressions

regexbuddy

 

Vadim and Gaev have reacted to this post.
VadimGaev

Thanks @mishem  the result is  ; ; ; ; ; ; ; ; ; ; but in fact it's not what I expected , I had also seen this result when testing on https://regex101.com/.

I don't really see any difference between split and list, I think replace (;8;85;89;55;77;;9;40;;5;57;37) is more what I'm looking for but it's not exactly what I want.

The problem is the same as with StrParse, single-digit numbers cause extra entries, so in my example my aim is to obtain an array of just 10 numbers.

@phil78

I have little experience with Regex; and the Help file does not include any examples of the StrRegexSplit/StrRegexList commands; so, I am not sure of the expected format of the "Variable for result-list" mentioned in the Help file.

Also, as you might know, VisualNEOWin (p.k.a NeoBook) does not really support true arrays (only something called Arrayed variables);

Is there a reason you are using the StrRegexSplit/StrRegexList commands ? I ask because StrParse and StrReplace would do what you are attempting to do e.g. this code ...

SetVar "[SpaceSeparated]" "8 85 89 55 77 9 40 5 57 37"

StrReplace "[SpaceSeparated]" " " ";" "[SemiColonSeparated]" ""

StrParse "[SemiColonSeparated]" ";" "[T11]" "[count]"

AlertBox "results" "SemiColonSeparated=[SemiColonSeparated][#13][#10][count][#13][#10]T112=[T112]"

... would show ...

8;85;89;55;77;9;40;5;57;37"
10
T112 = 85

Vadim has reacted to this post.
Vadim

Hi @gaev, thanks for reply, the reason why I tried RegEx is because  parse or replace does not give the good result for 1-digit numbers .

SetVar "[SpaceSeparated]" " 8 85 89 55 77 9 40 5 57 37"

StrReplace "[SpaceSeparated]" " " ";" "[SemiColonSeparated]" ""   ==> ;8;85;89;55;77;;9;40;;5;57;37 and not 8;85;89;55;77;9;40;5;57;37

StrParse "[SemiColonSeparated]" ";" "[T11]" "[count]"    ==> T112 = 8 ; [count] = 13 and not what I expect : [count] = 10, T111 = 8, T112=85....

You said VisualNEOWin  does not really support true arrays, is this the reason why we have problem when sending array as subroutine parameter ?

See https://visualneo.com/forum/topic/creacion-de-vbs-y-js-con-ai-entrenada-para-visualneo-win/

Quote from Phil78 on January 16, 2024, 6:53 pm

the result is  ; ; ; ; ; ; ; ; ; ;

SetVar "[T1]" " 8 85 89 55 77 9 40 5 57 37"
StrRegexSplit "\s+" "[T1]" ";" "[T11]"
StrRegexList "\d+" "[T1]" ";" "[T21]"

I didn't use the regular expressions correctly.
That's right.

@phil78

SetVar "[SpaceSeparated]" " 8 85 89 55 77 9 40 5 57 37"
StrReplace "[SpaceSeparated]" " " ";" "[SemiColonSeparated]" ""

==> ;8;85;89;55;77;;9;40;;5;57;37 and not 8;85;89;55;77;9;40;5;57;37

a) I did not experience the problem with single digits as you stated.

b) You have a leading semicolon because your source string ( [SpaceSeparated]) has a leading space character] ... if your source string includes a leading space character, you can ...

- either remove the leading space before issuing the StrReplace command
- or remove the leading semi-colon after issuing this command.

StrParse "[SemiColonSeparated]" ";" "[T11]" "[count]"

==> T112 = 8 ; [count] = 13 and not what I expect : [count] = 10, T111 = 8, T112=85....

I did not get the incorrect [count] value; note that a leading semicolon will cause the value to be one more than you expected, but not 3 more.

If you want, I can post a pub for you to check out on your machine.

mishem has reacted to this post.
mishem

Regex

SetVar "[SpaceSeparated]" " 8 85 89 55 77  9 40 5 57 37"
.Remove leading spaces, if any.
StrRegexReplace "^\s+" "[SpaceSeparated]" "" "" "[SpaceSeparated]"
.Replace two or more spaces, if any, with one.
StrRegexReplace "\s+" "[SpaceSeparated]" "[#32]" "" "[SpaceSeparated]"

StrRegexSplit "\s+" "[SpaceSeparated]" ";" "[SemiColonSeparated]"
StrParse "[SemiColonSeparated]" ";" "[T11]" "[count]"

Or

SetVar "[SpaceSeparated]" " 8 85 89 55 77  9 40 5 57 37"

StrRegexReplace "^\s+" "[SpaceSeparated]" "" "" "[SpaceSeparated]"
StrRegexReplace "\s+" "[SpaceSeparated]" "[#32]" "" "[SpaceSeparated]"

StrParse "[SpaceSeparated]" "[#32]" "[T11]" "[count]"

Or

SetVar "[SpaceSeparated]" " 8 85 89 55 77  9 40 5 57 37"

SubStr "[SpaceSeparated]" "1" "1" "[Space]"
While "[Space]" "=" "[#32]"
    StrDel "[SpaceSeparated]" "1" "1" "[SpaceSeparated]"
    SubStr "[SpaceSeparated]" "1" "1" "[Space]"
EndWhile

Loop "1" "2" "[i]"
 StrReplace "[SpaceSeparated]" "[#32][#32][#32]" "[#32]" "[SpaceSeparated]" ""
 StrReplace "[SpaceSeparated]" "[#32][#32]" "[#32]" "[SpaceSeparated]" ""
EndLoop

StrParse "[SpaceSeparated]" "[#32]" "[T11]" "[count]"
ClearVariables "[Space],[i]"

 

 

Vadim has reacted to this post.
Vadim

Thank you @mishem, your 2nd solution is the best for me !