Take out value form variable matchcollection

Hi,

I have been created variable type matchcollection where i got 3 column: First, Secend and Third. But i dont know how to take out one of the column. Can you guid me… the name of variable “x” so i need x… and what next to take out for example column first ?

Many thanks for help,
Regards,
@fudi5

matchcollection(0).ToString(), matchcollection(1).ToString(), matchcollection(2).ToString()

Regards,
Arivu

2 Likes

Hi @arivu96,

It dosen`t work. I got mesage: “Write line : Specified argument was out of the range of valid values.
Parameter name: i”

Regards,
@fudi5

Hi @fudi5,

how you used can you send the screenshot.

make sure the matchcollection should not be empty.

you can check using if condition matchcollection.Any
True->values available
False-> No data in the matchcollection.

matchcollection.count → you will get the collection data count.

Regards,
Arivu

@arivu96,

Im doing this:

1.windows assign
(x is variable matchcollection and
row(sekcja) looks like this:

3 10,11 1 -

)

system.Text.RegularExpressions.Regex.Matches(row(“sekcja”).ToString,“^(?<FIRST>(?:/\s)?(?:\w+(?:,\s\w+))|—)\s(?<SECOND>(?:/\s)?(?:\w+(?:,\s\w+))|—)\s(?<THIRD>(?:/\s)?(?:\w+(?:,\s\w+)*)|—)$”)

  1. writeline
    x(0).tostring

Regards,
@fudi5

Hi @fudi5,

can you tell me what value you will get??? in row("sekcja").ToString

Regards,
Arivu

Here:

i think no data match based on your regex pattern.

Use this link to test the regex pattern

Regards,
Arivu

Ok i know what can be wrong. Many thanks for help.

I`ll let know.

Regards,
@fudi5

I have been changed patter and now it take this case but still dosent work:

^(?(?:/\s)?(?:\w+(?:,\s\w+))|—)\s(?(?:/\s)?(?:\w+(?:,\s\w+))|—)\s(?(?:/\s)?(?:\w+(?:,\s\w+)*)|—)$

Hi @fudi5,
For testing regex pattern use the below link.

Regular Expression : ->your regex pattern
Test String → you input

Regards,
Arivu

@arivu96
I tested it before you sent link.

Now its working fine i just changed pattern.

Regards,
@fudi5

This is SOLUTION:
system.Text.RegularExpressions.Regex.Match(row(“sekcja”).ToString,"
(?(?:/\s)?(?:\w+(?:,\s?\w+))|—)"+
“\s”+
"(?(?:/\s)?(?:\w+(?:,\s?\w+)
)|—)"+
“\s”+
“(?(?:/\s)?(?:\w+(?:,\s?\w+)*)|—)”)

1 Like