-1

I had been searching a few sources online but none able to tell what this regex term matches for:

regex="^0-"

I knew ^ means starting of the string and 0 is just 0, but what is the meaning of - carrying behind? If it would mean just a literal char -, shouldn't it be written as ^0\- with a slash \ followed by a dash?

Besides, will this regex="Stain" matches both string: Stain and Sub-Stain?

Thanks Chun Meng

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
zyzy
  • 1
  • 2
  • the system filtered my "\" slash symbol. The complete sentence would be: "If it would mean just a char '-', shouldn't it be written as "^0\-" with the slash follow by the dash. – zyzy Sep 18 '14 at 07:42
  • What have you actually tried? https://www.debuggex.com/ – Gusdor Sep 18 '14 at 07:46

1 Answers1

0

regex="^0-" I knew ^ means starting of the string and 0 is just 0, but what is the meaning of '-' carrying behind? If it would mean just a char '-', shouldn't it be written as "^0-" with a slash "\" followed by a dash?

- not a regex special special character. So you don't need to escape - symbol. But you must escape - when it is used within character class. - inside character class acts like a range operator. ex, [0-9]

See also this question.

Besides, will this regex="Stain" matches both string: "Stain" & "Sub-Stain"?

Yes the regex Stain matches the string Stain and also the substring Stain in Sub-Stain

Community
  • 1
  • 1
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274