Replacing the number starting with one or more zeros and followed by a number with none. Here (?=\d), is positive look ahead which has zero width assertion. So it ll replace only the zeroes and not the following number.
Take a look at perlre and YAPE::Regex::Explain
For example:
$str = '004asdfsa'; #string starting with zero and followed by numbers
$str =~ s/^0+(?=\d)//;
print $str;
Output:
--------
4asdfsa
$str = 'a004asdfsa'; #not starting with zero
$str =~ s/^0+(?=\d)//;
print $str;
Output:
--------
a004asdfsa
$str = '0a4sdfsa'; #no number followed by zero
$str =~ s/^0+(?=\d)// ;
print $str;
Output:
--------
0a4sdfsa
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|