regex


$sr_no =~ s/^(0*)(.*)/$2/ , what does mean in perl script?


What is the meaning for the below substitution?
if($sr_no =~ m/^0/)
{
$sr_no =~ s/^(0*)(.*)/$2/;
}
It's a clumsy way of writing $sr_no =~ s/^0+//, that is, remove any leading zeros. The if is basically useless, as the substitution performs the same logic anyway (i.e. does not substitute if there is no match).
It strips leading zeros from a string.
Although I'd write it as
s/^0+//
i.e. replace one or more (+) leading (^) zeros (0) with nothing (//).
Replace all( due to *) preceding (due to ^) zeros by everything that followed them (due to $2 = (.*))
If the content of the scalar variable sr_no matches the regular expression ^0
that is, starts with a 0
Replace the text matching the regular expression ^(0*)(.*) with the second group
that is, remove leading 0s.
See also:
Perl regular expressions for background information about reguar expressions in Perl
Regexp Quote-Like Operators for detailed information about the m// and s/// operators.

Related Links

Removing 18 characters after a word on each line via Sublime Text
Regex group being too greedy
Postgres regexp replace not working
Converting text log file with data in quotes to individual columns, using RegEx
Splitting and select string starting with uppercase letter with Regex
Regular expression to return only alpha characters left of a character
Notepad++ replace last symbol in search regex
how to enforce a date format
Regex: txt vs tx?
Grok pattern for logs sent to logstash
Regex to fetch substring from a string
how to remove everything after [/img] with regex?
Windows Batch File Regular Expression
Select digits on the end of line
Need to make htaccess rule that blocks empty user agent unless the request contains a specific string
Regex to match different characters at same position in string

Categories

HOME
embedded-linux
vr
direction
word-vba
turing
antlr4
encog
c++14
android-bluetooth
socrata
autofac
prestashop-1.7
telnet
wso2ei
cross-compiling
cloudrail
watchservice
w2ui
gas
jmeter-plugins
slime
accelerated-mobile-page
abstract-syntax-tree
typemock-isolator
iar
text-parsing
f2py
valueinjecter
asana-api
svn2git
bluebird
json-c
kube-dns
sqlite.swift
complex-networks
stackexchange.exceptional
jackrabbit
decompiler
vue2
solid-principles
flags
runge-kutta
tibco-ems
h5py
gradle-tooling-api
nexus-5
spark-submit
keyboard-maestro
autofocus
oracle-aq
default-browser
asyncsocket
federation
fido
simple.odata.client
dump
libev
derbyjs
ice
android-identifiers
javascript-security
billing
autogen
angular-directive
asp.net-mvc-custom-filter
kombu
error-correction
building
xendesktop
duration
selenium2library
sqlj
python-dragonfly
android-gpuimageview
alienvault
crowdflower
fastparse
vraptor
adserver
android-tablelayout
boxapiv2
razor-2
gdk
express-jwt
syndication-feed
pkcs#10
xacml3
mydbr
b2b
requiredfieldvalidator
dotliquid
css3pie
acts-as-taggable-on
mongo-shell
nawk
android-lru-cache
vlfeat
resolver
shift
libnids
programmers-notepad
google-chrome-frame
python-dateutil
google-goggles
osmf
xml-dtd
noindex
junitperf
mate
retain
xmltextwriter
arraycopy
msn-messenger
sqlprofileprovider

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App