Regex to extract 2 first character from different patterns

Is this possible using a single eline regex patter ? thanks.

  1. IF contains no hyphen then get the first 2 characters
    input: FL123466
    output: FL

input: HL123466
output: HL

2.IF contains one hyphen then get first 2 characters after the hyphen.
input: A-CL123466
output: CL

input: AC-RL123466
output: RL

    1. IF contains two hyphens get the first 2 character after the first hyphen.
      input : W-AA-456789
      output: AA

input : RR-CA-456789
output: CA

what I have so far but I think this is too long



How about the following expression?




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