How do I only extract the characters before the second dash "-"?

I understand that we can extract a dynamic text by putting a * on the aaname

What if I only want to extract specific characters from this dynamic variable?

I.e. Variable is Global-Nordics-Sweden and I only want “Global-Nordics”

Hi!

The RegEx will work based on the pattern.

System.Text.RegularExpressions.RegEx.Matches(Input_String,"\S+(?<=-).*\S(?=-Sweden)")

FYI:

Regards,
NaNi

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"[^-]+-[^-]+").Value

Regards,

1 Like

Hi @andrea.ong

Follow the code given by @Yoichi , it should work dynamically

image

Thank you.

1 Like

Thanks @Yoichi @Jobin_Joy , do i input this line of code into the selector?

Please have a look at this.

Hope this will be helpful. Thank you.

Thank you so much for your response, @Jobin_Joy . I tried editing the selector like this but I’m not very confident in the syntax. Is this what you meant?

image

Hi,

If you want to use regex selector in aaname attribute, matching:aaname='regex' will work.

If it doesn’t work, can you share your target image? Please note selector is for identifying element. If you want to get partial string of the target, first get whole the string, then extract target using regex etc.

Regards,

Try to use javascript injector with the following xpath “//div[contains(@class, ‘xxxxx’)]” and select the specific node

Hi @Yoichi, this is the sample image

image

I’m afraid I’m a beginner at this so I’m probably asking really lame questions but… What exactly do I do to get the full string first then extract the target using regex?

Step 1: Use Get Text activity with aaname=“*” to extract full string
Step 2: …

Hi,

Can you try as the following image?

System.Text.RegularExpressions.Regex.Match(valueFromGetText,"[^-]+-[^-]+").Value

if you want to assign target string to variable, please use Assign activity.

Regards,

Awesome @Yoichi this works!! What if I don’t want a message box to appear and I just want the check to be run on the background? What activity do I use please?

Use write Line

Regards,
NaNi

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