• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex

 
joshua antony
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The output is

start: 1 group: 1+
start: 4 group: 3-
start: 7 group: 5=
start: 9 group: 45
start: 11 group: 45

I am not able to understand the last 2 lines of the output.
How come start: 9 group: 45
start: 11 group: 45 gets printed.

In this case we are searching for the first letter to be either 1,2,3,4 or 5 and the second one to be either _,- or =. isint it?
 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'+' is quantifier.
Maybe '-' is also quantifier too.
so

work.

Yours,
William
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case we are searching for the first letter to be either 1,2,3,4 or 5 and the second one to be either _,- or =. isint it?


Interesting mistake... I probably would have made it myself.

It's the "-". It has special meaning used to specify a range, such as [a-z]. In this case, [+-=] means the range from the "+" to "=", which in the unicode table, includes the numbers.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic