cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can anyone please help me with the following regex?

rajanikanthanka
Inactive

Hi,

I created a BT with a splitting measure to capture email information. I am able to capture email but @ symbol is missing in all of the splittings.

Below is my regex

\A((?:[\w+\-].?)+)@([a-z\d\-]+(?:\.[a-z]+)*\.[a-z]+)\z

My sample output:-

johnburke1235 gmail.com

dbarczuk25 gmail.com

Thanks,

Rajani

5 REPLIES 5

JamesKitson
Dynatrace Leader
Dynatrace Leader

The issue is that the @ is not included in any capturing groups (between parentheses). There's probably a few ways to fix it but in general you'll need to include the '@' within a group. Either add some additional parentheses around the leading and trailing parentheses already there or just surround the '@' with it's own set of parentheses. This link shows the former and you can see it is included in a capture group:

https://regex101.com/r/HV7BQW/1

James

James,

I am trying different ways but still @ is not capturing for some reason.

Tried

\A((?:[\w+\-].?)+)(@)([a-z\d\-]+(?:\.[a-z]+)*\.[a-z]+)\z but no luck. In regex101.com it is showing completely valid for any email id's but in client it is not taking this symbol.

Did you try the suggestion I included in that link:

\A(((?:[\w+\-].?)+)@([a-z\d\-]+(?:\.[a-z]+)*\.[a-z]+))\z

Apart from that I don't really have any more suggestions. Normally I'll just play with a couple variations until it works - I only have a working understanding of the details of regex. I can say for common use cases like this (matching an email) I would expect to find quite a few from a search online.

James,

I am using this regex

([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)

it is capturing all emails now with @ symbol.

Hi Rajani,

No need to use such horrendous regular expressions. As you are not validating regular expression but just capturing text. Use the boundaries of the fields than pattern.

Try this:

^(?:[^@]*)(@.+)$

Note: Regex put dtserver under strain, some may even cause lag in the purepath processing.

Regards, Rajesh