Get numbers between two strings

Hello!

I’m currently building my first bot and got stuck on this part of the process.

Basically, I need to fetch a series of numbers between two strings.
The strings are always the same, and the numbers are always 6 characters long and always starts with 6. But the amount of number values varies from 1 up to 100

So basically:
Start
612345
654321
678901
end

And I want the output to be in one row with a space between each number like this:
612345 654321 678901

I want to save this as a variable if possible

I hope you’re able to understand my request.

1 Like

Use regex function

“(?<=” + “first string” + “)(.*?)(?=” + “last string” + “)”

1 Like

You can use Regex pattern \d+ in Match activity and loop trough Regex Result to form the string

1 Like

number.xaml (5.0 KB)

Try this if its work

1 Like

and if they are in new line you can select “ignore white space” checkbox in match activity

1 Like

Your script works like a charm!

However, the full document that i need to get the numbers from contains additional numbers and fields that I dont want to be included.

Therefore I need it to specifically extract the data between “start” and “end” and nothing else.

And also, the number values are unique per document so I need it to fetch the string from the document and not have it pre-determined

1 Like

Edit:

I modified your script and now it works.
However when I tick the “ignore white space” checkbox it causes an error in the message box:
RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure ,
ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance,
Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment,
ActivityInstance activityInstance,
ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment,
ActivityInstance targetActivityInstance,
ActivityExecutor executor,
Object argumentValueOverride,
Location resultLocation,
Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument,
Int32 nextArgumentIndex,
ActivityExecutor executor,
IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides,
Location resultLocation,
Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

1 Like

its working fine now?? providing the desired result?

Almost!

The output looks like:
612345
654321
678901

But I want it to look like:
612345 654321 678901

But when I check “ignore white space” it fails to run

1 Like

@Hgren Replace Newline with space as follows

 Assign str = str.Replace(Environment.newline," ")

How do you mean?

1 Like

@Hgren Here you go with xaml file getNumbers.xaml (4.8 KB) .Let me know for further help.

1 Like

@Hgren its working

Still have the same problem.

I got it to fetch the numbers after assigning the text from the document to a variable with Read Text File.

But it still outputs them like this:
612345
654321
678901

And not like this:
612345 654321 678901

@Hgren Check this xaml

Yes I tried using this.
But in your example you have the text predefined in a variable,
Str = “start 612345 654321 678901”

But since this bot is going to repeat this process for multiple text documents I need it to use Read Text Document to define the variable.

@Hgren Can you attach sample text file or sample data

This is how the file looks:
OID: 12345 test
DID: 34214 test

Error message:
20190926 22:36:30 [0000000] (ERROR)
Split: 7

Affected messageIDs:
612345
654321
678901

Account.nr:: nill
Product:: nill

I need to extract the numbers between “Affected messageIDS:” and “Account.Nr”.
This I’ve solved.

I simply need the message Ids to be in a single row divided by a space and not on top of each other, like this: 612345 654321 678901

@Hgren Check this and let me know

getNumbers.xaml (4.7 KB)

1 Like

Hmm nope, just get a blank message box