• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression help needed

 
Prashant Langade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like "^_.*_$" should do the trick.
 
Eoin Brosnan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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). "^_.+_$"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic