Start a new topic

RegEx to prepend a default value to string IF NOT BLANK

 

Hello fellow RegExers,

 

 

Does anyone know of a useful regular expression that can prepend a default value to the beginning of an alpha-numeric string only IF NOT BLANK?

 

 

 

Example - If there is an actual value present in column X, then prepend "2016" to that value. If there isn't a value (blank) there, then do nothing but leave blank.

 

 

Many thanks for any advice! AB

AB!!

2016$1

(^.+$)

 

image

Wayne beat me to it...( I figured he would)

This works too, but his is better.
First line: Replacement value: 2016$& value to match on ^(?=\s*\S).*$
Second line: replacement value: -BLANK- value to match on: ^\s*$


nice John!

+ = "one or more" so mine just says "one or more of any character". In this case I am assuming that we would count spaces as characters.
Awesome!! It was for prepending before a team name, which could be open text and contain practically anything or be blank. Huge help, thanks to you both!!

AB
Login or Signup to post a comment