• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the meaning of below regular expression

 
subba rao
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the meaning of below regular expression

.*?(?:\\d-)+\\w+)/.*
 
John Jai
Rancher
Posts: 1776
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the help of java.util.regex.Pattern:
. means any character
.* means any character zero or more times
.*? means the "any" should be taken reluctantly
(?: is the start of a non-capturing group
\\d means a single digit
(?:\\d-) means a single digit followed by a -, as a non-capturing group
(?:\\d-)+ indicates that part should be taken one or more times
\\w means a single word character
\\w+ means one or more word characters
) is the closing of a group (capturing or not); it's start is missing here
/.* is a single / followed by anything

I think you missed one ( and the regex should have been .*?((?:\\d-)+\\w+)/.*. This would make the digits plus word characters a capturing group which can later be extracted. The regex would match things like dasdas1-a/dasdas, asdas1-3-bsdsa/dasdasdsa, etc; 1-a and 1-3-bsdsa would be captured by the group.

Note that the first part is reluctant, because otherwise the second string would have lead to 3-bsdsa; the 1- would be part of the .*.
 
subba rao
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the explaination ROB
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic