How To Extract Particular ID from a String

Hi Everyone,

I want to extract only 1st ID(AB123456) from the below text. The below pattern is fixed and I need only the 1st ID in between the ‘##’ symbols.
## #AB123456# #AT9876543#

Hello @Abhi15 ,

You can wither use regex expressions or split function to get the required data.

Please confirm whether the ID will always start with AB or please provide few more samples.

No The In ID may start with any number or letters, few examples below.
Eg: ## #2J7DMU00# #AT0388199#
## #70EQ2CP00# #AM3529053#

Also for some there won’t be the 1st ID in that case I need the output as empty or null. (Example: ## ## #FH3601019#)

lets assume we can rely on the #
then we can use following regex pattern

1 Like

regex.match(myStr.Replace("##",""),"\#.*?\#")

Removes the leading ## and then gets the first occurrence of text between a # and # character.

Hello @Abhi15 ,

The below method will extract the proper details. If the first id is there it will retrieve the ID, else Null.

Split(Split(Str," #")(1).ToString,"#")(0).ToString

image

@Rahul_Unnikrishnan Thanks that works fine and is satisfying my condition.

1 Like

Glad to hear that. :slight_smile:

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