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

Perl: How to match a string that is not in a given string [duplicate]
glob2rx in R to get all cells whose last decimal is 5?
Finding file names without a specified character
Perl: quick replacing of occurrences of multiple words in an array
Extract resolution from string
How do I create a Scala Regex that is compiled using Java Pattern.COMMENTS?
Is there a way to search terms in order with RegexpQuery in lucene?
Regex to allow any charcter EXCEPT backslash
Regex: Match a condition, then find the first occurrence of another condition that precedes it on the same line. Possible?
Regex for URL routing - match alphanumeric and dashes except words in this list
R: gsub and capture
Trouble with regex in Perl
Duplicate symbols in regular expressions
NSRegularExpression to remove the rest codes
Regex replace in sublimetext2
Regular Expression Search Replace all non leading tabs with single space Notepad++

Categories

HOME
amazon-s3
elastic-beanstalk
module
google-cloud-dataproc
turing
visual-studio-2012
encog
jbpm
coded-ui-tests
clion
sql-server-express
higher-order-functions
nservicebus
graph-tool
resolve
smartsheet-c#-sdk-v2
revitpythonshell
accelerated-mobile-page
azure-ad-graph-api
angular-services
stylesheet
temp
coqide
clappr
panel-data
groove
stackexchange.exceptional
tensor
webcenter
haxm
decompiler
qweb
knowledge-management
pac
logicblox
automata-theory
nexus-5
distributed-lock
opal
move
federation
html-lists
fasta
typesetting
billing
getelementbyid
postmark
ipmi
tachyon
ipopt
perspective
mit-scheme
vb4android
groupbox
occam-pi
rdotnet
hypervisor
tabbar
base-conversion
ehcache-bigmemory
generalization
newsql
iscroll4
tab-delimited
jasmin
liferay-hook
syndication-feed
dotliquid
data-dictionary
jquery-mobile-popup
modx-evolution
external-dependencies
jquery-data
scrollpane
google-authorship
html5-apps
northwind
square-cube
shebang
12factor
oncreate
doophp
calloc
arden-syntax
rgba
ms-access-97
c++builder-xe2
ruby-1.9.2
jetspeed2
regexbuddy
scramble
xtratreelist
dynamic-websites
templatebinding
greensoftware

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