Regex issue Using Options

Hi Guys,

I’m trying to extract value using a regex, but get some issues to use RegexOptions.*

For example: i want to get this “ELY A”. The space between “Y” and “A” can be space(s), backline,…

-----------------> So the expression will be something like: “ELYA\s{1,}E”

But Instead of using “\s”, i want to use “RegexOptions.IgnorePatternWhitespace”

Extras: What is the syntax to add multiple regexOptions in uipath? Is it correct?

Regex.IsMatch(mystring,"",RegexOptions.IgnorePatternWhitespace and RegexOptions.IgnoreCase )

Ty for your help,
Cheers.

Sorry buddy
I don’t get this example
One more pls

Cheers @Elya

1 Like

@elya - i don’t quite understand what you’re trying to achieve with your example as it’s a bit unclear. However, i can answer this part:

Extras: What is the syntax to add multiple regexOptions in uipath?

You need to use an OR statement. So it would be Regex.IsMatch(StringToCheck,RegexPatternAsString,RegexOptions.IgnorePatternWhiteSpace Or RegexOptions.IgnoreCase)

1 Like

Sur!

exempleRegex.7z (8.7 KB)

@elya - i am not able to open .7z files as i can’t download new applications, it’d have to be .zip instead.

However, why do you want to use the ignorepatternwhitespace option? What is wrong with using \s? that is a lot more simple I’d imagine. Just use the following expression if there is a possibility for no whitespace: ELY\s*A or ELY\s+A if you only want to find matches where there is at least 1 whitespace. Both patterns will pull out any type of whitespace character no matter how many there are between the ELY and the A

yep, because i ve many of Elya.
Like : x= elya, y:dave,z=…
So my regex will look like regex.ismatch(mystring,x)

So is for that i prefered to use options instead of \s —> to not use x.replace(" “,”\s) or idk

Got it
Hope this expression would help you resolve this
Str_output = System.Text.RegularExpressions.Regex.Match(str_input,”ELY.*(?>A)”)

This will get the match value and store that to str_output string variable

Cheers @Elya

@elya the 2 expressions above (one with asterisk * and one with plus +) both do exactly what you’re asking? Is there a reason why the expression will not work for you that I am misunderstanding? If so, perhaps you could give a sample input text and your expected result you want to pull out with regex. We’d need something longer than what was provided as sample input text in the first post though

@Palaniyappan your example will not capture the letter A and will also capture all the garbage (any character, not just whitespaces) in the entire input string between ELY and the next letter A, even if it isn’t what the OP was hoping to get

1 Like

Sur! example.txt (85 Bytes)
Ty to catch this fake iban account.

So your input text is:

Invoice description : ELECTRICITY DELIVERY IBAN : GB36 DEUT 3636 3737 3838 
00

What do you want to pull out from the input text? I don’t see ELY A anywhere, so it must be something different, correct?

Of course Elya is just my nickname. I want to pull out “GB36 DEUT 3636 3737 3838 00”
But not using “GB36 DEUT 3636 3737 3838\s{1,}00”

The cleanest way is to use this string 'GB36DEUT36363737383800"

Based on your input text and your expected output I don’t think Regex is the best solution. I would instead use string.split

If the text you want is always going to be preceded by ELECTRICITY DELIVERY IBAN : then you should split on that text, take the 2nd string in the array, and trim it. That would give you your desired answer of “GB36 DEUT 3636 3737 3838 00”. If you want to remove the spaces, just use a .Replace(" ",string.empty) on this string

This assumes the preceding text is always constant, and you want to pull out all of the text afterwards. You’d have to make a few changes if either of these assumptions are incorrect

I dont want to remove space. I want to find "GB36 DEUT 3636 3737 3838 00”
from "GB36DEUT36363737383800”, and this 1 of 100 account i ve to find. And all of them could be like that: “GB36DEUT363637 37383800”
“GB36DEUT36363737383
800”
“GB 36 DEUT 3636 3737 3838 00”

So if the input is
str_input = “Invoice description : ELECTRICITY DELIVERY IBAN : GB36 DEUT 3636 3737 3838
00”

Then output is
Str_output = Split(str_input,”:”)(2).ToString.Trim.Replace(“ “,””)

Cheers @Elya

example.txt (6.0 KB)

All of this information is needed for us to help. The more information you provide, the easier it is for us to help with a solution.

It sounds like you have a list of strings, and you are trying to find matches for each string in that list within the Input Text. Is that correct? If so, I’d go about it like this.

  1. Clean up the input text to remove spaces. Create a new string called InputStringNoSpaces and use an assign activity as follows: Assign InputStringNoSpaces = new String(InputString.Where(Function (x) Not Char.IsWhiteSpace(x)).ToArray())
  2. Create a new list of strings i’ll call MatchedStrings. Assign MatchedStrings = new list(of string)
  3. For each str in MyListOfStrings
    a. If InputStringNoSpaces.ToUpper.Contains(str.ToUpper) Then add str to MatchedStrings collection (use add to collection activity)
  4. Now you have a list of all the strings that were matches.

If you don’t have a list of all the strings you’re trying to match then we would do something else. I’m having to make a lot of assumptions because we are being provided very limited information.

If you just want to pull out from InputText all of the items that look like they are IBANs, then it appears they all follow the same pattern. I would do it as follows:

  1. Remove all the spaces from InputText like we did in step #1 above
  2. Assign IBANmatches (this is an ienumerable matches variable) = Regex.Matches(InputText,"[A-Za-z]{2}\d{2}[A-Za-z]{4}\d{14})
  3. Assign IBANnumbers = new list(of string)
  4. For each IBAN in IBANmatches
    a. add to collection activity (TypeArgment string): IBAN.value

Now you have pulled out all IBANs from the input text. This assumes it follows the pattern specified in the regex expression

1 Like

Ty @Dave and @Palaniyappan for you.

@Dave like u said i just need to remove all space before using my regex :slight_smile: Easy*

I could give you the good documents, 'cause is too confidential…

1 Like

But I still dont know why RegexOptions.IgnorePatternWhiteSpace didn"t work…

“GB36DEUT36363737383
800”

@elya that just ignores whitespace in your pattern, it doesn’t ignore whitespace within the InputText. It’s generally only used if you have a complex regex pattern and you use whitespace to help make it more readable. It’s very rarely used in my experience, because if your regex is that complicated, it should probably be broken down into multiple regex anyways

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.