-3

Test String -

COAW983742892 COBW98374289

Regular Expression -

^(COBW|COaW|COXW)[0-9]+

Matching String is -

COAW983742892

My question is , why it don't match the both strings?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

1

Your regex suggests that it should be the start of the String with ^ symbol at the start of regex.

Try this regex -

(COBW|COAW|COXW)[0-9]+

It will match both the strings.

gohil90
  • 517
  • 5
  • 16
0

You started your regex from ^ (the start of the string), so the only content likely to be matched is the initial part of your source string.

Remove the starting ^ from the regex and it will match both substrings.

I assume that:

  • you use g option,
  • the true content of your regex is COAW (you changed A into a by mistake), otherwise set i option.
Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41