Good day. Tell me please. What regular expression will help me replace every 1st character in a line if it is not "-" with "+". The string can be either 1. 00000000000 or 2. -0000034544 Thank you.

  • one
    What does each first character mean. those. all characters except + -? /[^-]/ - Mike
  • Yes, it is assumed that there will most likely be "0". - Evgeniy A
  • Then do not call him everyone because there is only one 1st character in the line. And every first one is all symbols. One replaced, following him again first - Mike Nov.

1 answer 1

So do as said. Just change the first character to + if it is not - (to the heap and not + ):

 $string =~ s/^[^-+]/\+/;