473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Regular Expression - drive me crazy

13
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.
Expand|Select|Wrap|Line Numbers
  1. my $pattern = "J??[!G]?[!R,!L]EB*[E,H,K,W,L]"; 
  2. my $data1 = "JMNPAVEBL";  # should match with the pattern 
  3. $pattern =~ s/\,/\|/g; 
  4. $pattern =~ s/\*/\.\*/g; 
  5. $pattern =~ s/\?/\./g; 
  6. while ($pattern =~ /\[\!.*\]/) { 
  7.     $pattern =~ s/\[\!(.*)\]/\(\?\!\[\#\]\)/; #something is really wrong here!
  8.     my $subpattern = $1; 
  9.     $subpattern =~ s/\!//g; 
  10.     $pattern =~ s/#/$subpattern/; 
  11. }
  12. print "Trying to match $data1 with $pattern\n";
  13. if ($data1 =~ /$pattern/i) { 
  14.     print "Found a match!\n"; 
  15. else { 
  16.     print "No matching found!\n"; 
  17. }
Nov 18 '08 #1
3 2099
nithinpes
410 Expert 256MB
The pattern for your requirement will be something like:
Expand|Select|Wrap|Line Numbers
  1.    /J..[^G].[^RL]EB.*[EHKWL]/
  2.  
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.
Nov 18 '08 #2
ahgan
13
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!
Nov 18 '08 #3
nithinpes
410 Expert 256MB
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.
Nov 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
6
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...
1
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...
4
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...
2
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 ...
3
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,...
7
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...
25
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...
3
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...
3
jlm699
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...
0
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...
0
isladogs
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.