Hi experts,
How do I use regex to extract 1 and 2 from the list of documents ie:
Document ABC v1
Document ABC v2
I have to use the numbers to do comparison
thanks.
Hi experts,
How do I use regex to extract 1 and 2 from the list of documents ie:
Document ABC v1
Document ABC v2
I have to use the numbers to do comparison
thanks.
Hi @sophiey
Try this:
Assign-> documentNames = New List(Of String) From {"Document ABC v1", "Document ABC v2"}
Assign-> numbers = (From doc In documentNames Select Integer.Parse(System.Text.RegularExpressions.Regex.Match(doc, "\d+").Value.Trim())).ToList()
documentNames
and numbers
are of DataType System.Collections.Generic.List(System.String)
documentNames-> refers too the list variable where you get doc names.
Hope it helps!!
HI,
If you need just the last character, the following will work
yourString.Last.ToString
If there is possibility to get 2 or more digits numbers, the following regex works.
System.Text.RegularExpressions.Regex.Match(yourString,"\d+$").Value
how do i ensure only extract the last version number and not the numbers in front?
ie:
System2 document v1
and also possible to get version number like this 2.0 and 2.5 (with decimal)
HI,
The above regex (\d+$
) extracts only the last digits because $
means end of the string.
and also possible to get version number like this 2.0 and 2.5 (with decimal)
Can you try the following?
System.Text.RegularExpressions.Regex.Match(yourString,"[.\d]+$").Value
Regards,
Hi,
Hope below pattern will work for you.
(?<=Document ABC v+)\w+
Cheers…
Looks like v is laways present can use that
(?<= v)\d+
System.Text.RegularExpressions.Regex.Match(string,"(?<= v)\d+").Value
Cheers
Hi @sophiey
Every document name is ends with number only then we can use ends with function in regular expression, Check the below one which extracts the last number in the document name,
- Assign -> Input = "Document ABC v1"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(Input.toString,"\d+$").Value
You can use for each activity to loop through each document in the list, Inside for each you can use the assign activity to get the last number of each item.
Check the below workflow for better understanding,
Hope it helps!!
it works now. now I have the list of numbers.
how do i compare all of them to get the highest number?
Which type of the list? If it’s List<string>
, the following will work.
listNumber.OrderByDescending(Function(s) CDbl(s)).First()
Regards,