• 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

Regex pattern

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Suppose i have a url http://*.abc.com and i want to extract * from it, * can be anything, what would be the regex pattern for it
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Youknow we don't simply hand out answers. Besides, I don't know offhand. There are lots of regular expression resources; I presume you have been through the Java Tutorials which is a good introduction. Another useful link is http://www.regular-expressions.info/.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see why you need a regex at all. You are just looking for the substring which you get by dropping the first 7 characters and the last 8 characters.
 
Jacob Sonia
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

But the abc.com can be anything.

Thanks,
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacob Sonia wrote:But the abc.com can be anything.



Anything? Then it isn't possible to produce such a regex. All we know about the text is that it's http:// followed by something-1 followed by a dot followed by something-2. And since both of something-1 and something-2 can themselves contain a dot, the requirements are ambiguous. You'll need to improve on your requirements before you can get anywhere.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basically you need everything after the first dot?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are given "http://foo.bar.abc.com" do you want to extract "foo" or "foo.bar"?

Either way, you can do this with just string manipulation. No regex necessary. Just do a substring.

You just need to find the right indices to pass in, and String has plenty of methods to figure those out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic