How to use spilt or regex? Please guide me

I have a question?

I have a variable that contains a value like this

  1. "Marsh-India-Hyderabad 28/00/00, KPHB, Hyderabad, Telangana, 500072, India"
  2. "Aon ABC 55 11/22/33 Banjarahills Hyderabad Telangana 500081 India"

From the above value, I want value like
1.Marsh-India-Hyderabad
2.Aon ABC 55

Please help me.
Regards,
Reddy.

Hi,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(yourString,".*?(?=\s28/00/00)").Value

Regards,

1 Like

But the Address also different each and every time.

Hi,

If string always has nn/nn/nn format (like 28/00/00 or 11/22/33), the following will work. Can you try this?

System.Text.RegularExpressions.Regex.Match(yourString,".*?(?=\s\d{2}/\d{2}/\d{2})").Value

Regards,

What if address contains like this?
Marsh-England-Maidstone 100 Kings Hill Avenue, West Malling, Maidstone, Kent, 111111, United Kingdom,Active

Hi,

We need to find some rule to extract target string.
If you can accept multiple steps, the following might fit for you.

  1. If string contains nn/nn/nn, use the following expression.

System.Text.RegularExpressions.Regex.Match(yourString,".*?(?=\s\d{2}/\d{2}/\d{2})").Value

  1. If not contains ( in case that result of 1 is empty), use the following, for example.

System.Text.RegularExpressions.Regex.Match(yourString,".*?(?=\s\d+)").Value

Regards,

Summary

Marsh-England-Edinburgh Northumberland Street, North East Lane, Edinburgh, EH3 6LN, United Kingdom, Active

For above value it is not working and one more thing at address part the value is dynamic for every time, sometimes it contais some format and some times it contains another format. It it dynamically changing

Hi,

As i mentioned, we need to find some rule to extract target string.
If we cannot find it ,it’s difficult to extract it using regex etc, I think.

Regards,

Try this regex expression

[\w\-\ ]+(?= \d{2}\/\d{2}\/\d{2})|(\w+\-\w+\-\w+)

Let me know where it fails.

Is it possible to get the value in a better format? Always look for ways to improve the process itself rather than just deal with bad data.

you mean like this
System.Text.RegularExpressions.Regex.Match(Broker,"[\w-\ ]+(?= \d{2}/\d{2}/\d{2})|(\w+-\w+-\w+)").Value

Yes.

Ok I will check

Hi It is giving null value

System.Text.RegularExpressions.Regex.Match(Broker, "[\w\-\ ]+(?= \d{2}\/\d{2}\/\d{2})|(\w+\-\w+\-\w+)").Value

Copy from this

1 Like


Yes still giving me null or empty value.

Try Using matches activity.

In this activity you can check your regex result as they get higlighted

Use for loop to get the result

image