• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the meaning of below regular expression

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the meaning of below regular expression

.*?(?:\\d-)+\\w+)/.*
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any particular part you were not able to relate to http://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html and http://docs.oracle.com/javase/tutorial/essential/regex/quant.html?
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the explaination ROB
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic