aspose file tools*
The moose likes Beginning Java and the fly likes Regex pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regex pattern" Watch "Regex pattern" New topic
Author

Regex pattern

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174

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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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/.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: Jun 28, 2009
Posts: 174
Hi,

But the abc.com can be anything.

Thanks,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So basically you need everything after the first dot?
Steven Schwab
Greenhorn

Joined: May 25, 2010
Posts: 9
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex pattern