• 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

Anything wrong this regular expression

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rancher :
I want use apache RE to parse the string like

and get
XXX : YYY aaa : bbb as the result (XXX YYYY can be any character even japanese or chinese)

I write the regular expression like (<span>([^:]* : [^:]*)</span> *
it only give me the aaa : bbb, it confuse me a lot, how to implement this in right way?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hard to tell what the Regex is -- since you forgot to turn off the smilies. But from what I can read, it looks like you are using a qualifier at the end.

Anyway... When a subgroup matches multiple times, in a single match, due to a qualifier, then only the last match is retained. If you want all matches of a particular subgroup, I suggest you remove the qualifier, and iterate through multiple times with the find() method.

[EDIT: Sorry, just realized you are not using the built-in Regex engine. Hopefully, Apache has an equivalent that allows the iteration.]

Henry
[ May 11, 2006: Message edited by: Henry Wong ]
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


still only the bbb : ccc

how to get both?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please turn off the smilies -- it is a checkbox at the very bottom of the post page.

Henry
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved the problem with this regular expression

[^<]* : [^>]*

any better idea?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zee Ho:
I resolved the problem with this regular expression

[^<]* : [^>]*

any better idea?



It would depend on how strict you want the search. For example, if you want exactly one ":". And it must be between "<span>" and "</span>, then you could do this...



If you also want to prevent the "<" and ">", while at the same time, prevent matching the case where the ":" is missing, then you could do this...



Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic