Extract substring

How can we extract date from a string having underscore.
Str = “1234_New Jersey_XYZ_YTRD_051619”

Need to extract digits before first underscore in a variable.
PS: Number will vary it can be any number of digits.

Also, need to extract data between 3rd underscore & 4th underscore in a seperate variable.

Use regexp : regex101: build, test, and debug regex and extract the groups you need

image

(\d+)_.*_.*_(.*)_
1 Like

Hi @rohitgupta7879,

You could try also using the string manipulation.

StringArray = TestString.Split({“_”},StringSplitOptions.None)

Output:
FirstUnderScore = StringArray(0) - 1234
ThridUnderScore = StringArray(3) - YTRD
FourthUnderScore = StringArray(4) - 051619

Regards,
Sasikumar K