regex


Search if a string matches with any regex of an array in Perl


I have an array containing some PCRE matching patterns (like "prefix_.*") and I'm comparing a string with all the patterns of the array.
Currently, I'm working with this code:
foreach (#matchingPatterns) {
if ("$string" =~ "$_") {
[do something]
}
}
This code is working well but I'm sure that there is a prettier way to do that in Perl (without any loop?).
Am I wrong? ;)
There's not much scope for improvement here, but I'd be more liable to write something like one of the following:
for (#matchingPatterns) {
next if $string !~ /$_/;
# do something
}
or
for (grep { $string =~ /$_/ } #matchingPatterns) {
# do something
}
...both of which at least save you a few lines of code.

Related Links

Extract string after a symbol in Perl
Apply function to NA matrix in R
Using $groups to define TokenRegex rules
Password validate regex [duplicate]
Regex starting with 5, excluding specific preceding numbers, and 6 characters in length
Regex to match uppercase Expressions and Words
What is wrong with this regex in my rule redirect? (web.config)
remove all commas between quotes with a vim regex
Python program and regex
bash script for sorting files
print lines between patterns individual separate files
Regular expression (RegEx) not working
Vim search replace regex + incremental function
How can i write a regex for googlebot redirection in nginx
AWK: Extract string between two different patterns
Need simple regex (regular expression) for dynamic expression

Categories

HOME
typescript
odoo-10
google-apis-explorer
lua
order
apacheds
passwords
weight
wxpython
wikipedia
intel-xdk
box
windows-server-2012-r2
sweetalert
entity
tin-can-api
add-in
apache-spark-sql
h2o
superfish
bluej
nservicebus
lighttpd
ellipse
installer
apache-kafka-streams
raspberry-pi2
afnetworking-2
orientdb-2.1
stackexchange-api
slowcheetah
advantage-database-server
realm-java
similarity
jet
ormlite-servicestack
ibm-datapower
urlrewriter.net
mouseevent
wso2cep
mathdotnet
regex-group
apscheduler
directx-12
scom
background-process
vrtk
blockui
server-sent-events
jformattedtextfield
folly
plasticscm
procobol
essbase
tern
ewsjavaapi
clientscript
multisite
formstack
xssf
node.js-tape
paypal-webhooks
sshd
hipi
kombu
plotrix
ipopt
measurement-protocol
jsbin
cglib
agents-jade
file-management
pypyodbc
trello.net
strace
pakyow
illegalstateexception
dnx
samsung-gear
ironmq
gulp-rename
double-quotes
vbo
pegkit
mkpolyline
gcovr
horizontalscrollview
imake
excel-charts
laravel-validation
syndication-feed
blueprint
simpleaudioengine
libnids
broadcom
geometry-surface
gdb-python
uptime
hamlc
documentviewer
oledbcommand
hpple
httpcontext.cache
magento-1.5
android-assets
jetspeed2
datatemplate
emacs-ecb
replay
jtemplates
staging
hunchentoot
alivepdf
winamp
adbwireless
program-transformation
polyglot
help-authoring

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