File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regular expression help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular expression help needed" Watch "Regular expression help needed" New topic
Author

Regular expression help needed

Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi

I dont have much knowledge of Regular expressions.

My requirement is to match the string starting and ending with underscore i.e "_"

that means

if i have strings as
1> _abc_
2>_abc_av
3>ab_abc_
4>_pqr_

then only _abc_ and _pqr should be able to match the pattern.
Can any one please help me?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Something like "^_.*_$" should do the trick.


Ping & DNS - updated with new look and Ping home screen widget
Eoin Brosnan
Ranch Hand

Joined: Dec 12, 2009
Posts: 37
Ulf Dittmer wrote:Something like "^_.*_$" should do the trick.


"^_.*_$" will also match __ (two underscores, with no string). If you don't want that then just replace the *(which means zero or more) with +(which means at least 1 or more). "^_.+_$"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular expression help needed
 
Similar Threads
Multiple file output with JDK 6 XSLT implementation
HibernateTools Generating Wrong Code
Using contains/equals/== with random characters?
javascript event ?
Regular expression to search for words not beginning with a single quote and with or without spaces