My current regex query is
    (?P<TestName>(?<=_)[^\s]+)
Its able to capture "ABCD" and "Adjust_Path". I would like to capture the string "LED" as well from the list below
    4039_ABCD
    LED
    2020_Adjust_Path
My current regex query is
    (?P<TestName>(?<=_)[^\s]+)
Its able to capture "ABCD" and "Adjust_Path". I would like to capture the string "LED" as well from the list below
    4039_ABCD
    LED
    2020_Adjust_Path
(?<=_)[^\s]+)|((?!.*_)[^\s]+)
| : for the 2 cases (alternatives)
(?!.*_) : second case : not every string with a _
More info
You might assert an underscore to the left, and match any char except a whitespace char or underscore till the end of the string.
(?P<TestName>(?<=_)\S+|[^\s_]+)$
The pattern matches:
(?P<TestName> Named group TestName
(?<=_) Positive lookbehind, assert _ directly to the left\S+ Match 1+ times a non whitespace char| Or[^\s_]+ Match 1+ times any char except _ or a whitespace char) Close group TestName$ End of stringSee a regex demo.
If there has to be a digit present before the underscore:
(?P<TestName>(?<=\d_)\S+|[^\s_]+)$