String handling with miscellaneous characters


I’m studying string manipulation to find a solution for my project, but I can’t find anything that fits perfectly with what I need. can someone point me the way?

I need to find the order number between an information set.

-the string may appear as PEDIDO: Pedido: Ped:

-does not have a specific amount of characters and can be at the beginning or end of the string

Valor Imp. Aprox.: Federal 60.13 Estadual 82.16 Municipal 0.00) Fonte: IBPT Solicitacao: 1ssss6 Pedido: 020477;cst 060 ref. ICMS ret. p subst. tributaria decreto 42303 10 conforme anexo 1.PROCON RJ TEL: 151 ALERJ Tel: 0800 282 7060 MACAE(22)2759 0801 Rua Velho Campos,734 Centro Macae RJ

PEDIDO: 18.0000044-A|ENDERECO ENTREGA: ffffffffffffffffffffffffff - BffffffffffXO - RJ. CEP: 2dddddddd20|CENTRO DE CUSTO sss.|(Vendedor: dddddddddddddd) (N Pedido Cliente: Lsssss)|.|</

Boa tarde~

Hmmmm this is a tough one, not because of the beginning of the string, but the end of the string.

In order to get the string, you could use an OR statement to specify PEDIDO: OR Pedido: OR Ped: but the variable holding the string would have to know where to end… but I’m guessing since your documents are coming from all different sources, it isn’t standardized what comes ‘after’…



That’s right, everything in this string string will be variable and the order number only appears in this field.

I Tried

System.Text.RegularExpressions.Regex.Match(infCpl,“(?<=Pedido: ).+”).ToString

works, but only for “Pedido:” and not to “PEDIDO:” and also returns everything after the number

1 Like


Regex can do this. It has a setting to ignore case, and you can use ORs when there are multiple delimiter characters possible.

I think an OR can be accomplished in two ways…
"\;|\|" or "[\;\|]", where the '\' allows special characters basically

Then, you’ll need the look behind and look ahead

You’ll also need ‘?’ so it will not be greedy, as it will only look at the first match that comes up.

Finally, you just need the IgnoreCase option

System.Text.RegularExpressions.Regex.Match(str, "(?<=((pedido|ped)\:\s))(.+?)(?=([\;\|]))", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value.Trim

EDIT: made mistake in pattern, left off a parenthesis


1 Like


@ClaytonM exactly what is needed where I can find more information about regex. Do you know any good to indicate?

thank you

1 Like

For this solution, I didn’t really use any resource, so over time I just kind of remember a few useful tricks and double check the solution using a Write Line or MsgBox. Before that, I would “Google” how to do a certain thing in Regex .net.

The non-greedy ‘?’ on .+? or .*? was a recent thing I learned.

The RegexOptions such as IgnoreCase is actually a part of the syntax if you look inside UiPath with the rollover popup message while typing it out and is optional.

The look behind and look ahead is something (if I can’t remember) which is easily googled.

Sorry, I don’t have specific links or anything.


1 Like is a decent link I think many use and also has some references.

1 Like


thanks. I will use about :slightly_smiling_face:

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