I am trying to do a pattern matching for some setup being done previously by others but I thing I got it all wrong. Is there a simpler way of doing this?
For example:
PATTERN: J??[!G]?[!R,!L]EB*[E,H,K,W,L] means start with J 2nd & 3rd & 5th characters are wildcard matches 1 4th character is not a "G" 6th character is not an "R" or "L" 7th-8th character match "EB" 9th character is a wildcard matches zero or more follow by a match of either E, H, K, W, or L. - my $pattern = "J??[!G]?[!R,!L]EB*[E,H,K,W,L]";
-
my $data1 = "JMNPAVEBL"; # should match with the pattern
-
$pattern =~ s/\,/\|/g;
-
$pattern =~ s/\*/\.\*/g;
-
$pattern =~ s/\?/\./g;
-
while ($pattern =~ /\[\!.*\]/) {
-
$pattern =~ s/\[\!(.*)\]/\(\?\!\[\#\]\)/; #something is really wrong here!
-
my $subpattern = $1;
-
$subpattern =~ s/\!//g;
-
$pattern =~ s/#/$subpattern/;
-
}
-
print "Trying to match $data1 with $pattern\n";
-
if ($data1 =~ /$pattern/i) {
-
print "Found a match!\n";
-
}
-
else {
-
print "No matching found!\n";
-
}
3 2099
The pattern for your requirement will be something like: -
/J..[^G].[^RL]EB.*[EHKWL]/
-
Note that '.' will match any character. If you want it to be alphabetic only use [A-Z] instead.
The requirement for 9th character is not very clear-"9th character is a wildcard matches zero or more", Zero or more of what?
However, it would be good if you try to understand regular expressions before posting any further question.
To understand regular expressions better, consider going through perlre.
Hi nithinpes,
The 9th character is a wildcard zero or more of anything. My confusion is to detect the !G and !R,!L. I didn't know it's translated into [^G] and [^RL]. I thought ^ is for beginning of string. Now I know it can be used to negate the character class. Please forgive my ignorance and thanks for the solution!
Hi nithinpes,
The 9th character is a wildcard zero or more of anything. My confusion is to detect the !G and !R,!L. I didn't know it's translated into [^G] and [^RL]. I thought ^ is for beginning of string. Now I know it can be used to negate the character class. Please forgive my ignorance and thanks for the solution!
^ is for beginning of string. But when it it used within character class [], it stands for negation.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fuzzyman |
last post by:
I'm writing a song lyric database (effectively to drive a projector -
so the database contains the full song lyrics).
I'm using a nice simple Python database called KirbyBase which uses
regular...
|
by: Chris Lasher |
last post by:
Hello,
I would like to create a set of very similar regular expression. In
my initial thought, I'd hoped to create a regular expression with a
variable inside of it that I could simply pass a...
|
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make...
|
by: Buddy |
last post by:
Can someone please show me how to create a regular expression to do the
following
My text is set to
MyColumn{1, 100} Test
I want a regular expression that sets the text to the following...
|
by: Chris W. |
last post by:
I'm having a problem and it's driving me crazy. This code does
not work when run under VB.NET, but it works in 2 regular expression
evaluators. Am I missing something here?
Chris
...
|
by: rodchar |
last post by:
hey all,
what would my expression look like if i wanted to make sure that the input
matched the following pattern.
c:\filename.ext
it doesn't have to be the c drive just a letter, colon,...
|
by: Billa |
last post by:
Hi,
I am replaceing a big string using different regular expressions (see
some example at the end of the message). The problem is whenever I
apply a "replace" it makes a new copy of string and I...
|
by: Mike |
last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in
matches. I would like to get what the actual regular expression is.
In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
|
by: fgarciarico |
last post by:
I'm getting crazy with a problem using regular expression. I wanna
search a string into a text and replace it the found string with the
next code, but it doesn't work and I don't know why:
new...
|
by: jlm699 |
last post by:
I have an application that is build on wxPython and have run into a small but annoying problem. I use a Search Control in my toolbar just as in the ToolBar example. Now when the user enters say...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |