File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Regular expression help needed

Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 73

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_

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

Joined: Mar 22, 2005
Posts: 42965
Something like "^_.*_$" should do the trick.
Eoin Brosnan
Ranch Hand

Joined: Dec 12, 2009
Posts: 42
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:
subject: Regular expression help needed
jQuery in Action, 3rd edition