wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 41572
    
  54
Something like "^_.*_$" should do the trick.


Ping & DNS - my free Android networking tools app
Eoin Brosnan
Ranch Hand

Joined: Dec 12, 2009
Posts: 40
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). "^_.+_$"
 
 
subject: Regular expression help needed