473,324 Members | 2,257 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,324 software developers and data experts.

Help on Regex

rajiv07
141 100+
Hi to all,

I have regex related pl fie below.when i execute the file it gives some error.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. my @array=('3242342','fdsfsd4432');
  3.  
  4. my $file='D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI(ZEHREELA INSAAN.wma';
  5.  
  6. my @ee=grep(/^$file$/,@array);
  7.  
  8. print @ee;

My error

Unmatched ( in regex; marked by <-- HERE in m/^D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI( <-- HERE ZEHREELA INSAAN.wma$/ at C:\DOCUME~1\INDIAM~1.COM\LOCALS~1\Temp\locB8.tmp line 9.

Please Help on this.

regards Rajiv.
Jun 2 '08 #1
4 1533
rajiv07
141 100+
I got the point now if the string contain regex special character like $,^ ) we have to escape the character.

Regards
Rajiv
Jun 2 '08 #2
nithinpes
410 Expert 256MB
Hi to all,

I have regex related pl fie below.when i execute the file it gives some error.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. my @array=('3242342','fdsfsd4432');
  3.  
  4. my $file='D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI(ZEHREELA INSAAN.wma';
  5.  
  6. my @ee=grep(/^$file$/,@array);
  7.  
  8. print @ee;

My error

Unmatched ( in regex; marked by <-- HERE in m/^D:/HTTP/sample/SAREGAMA/HINDI/01/INH100155170 O HANSINI( <-- HERE ZEHREELA INSAAN.wma$/ at C:\DOCUME~1\INDIAM~1.COM\LOCALS~1\Temp\locB8.tmp line 9.

Please Help on this.

regards Rajiv.
Change this line:
Expand|Select|Wrap|Line Numbers
  1. my @ee=grep(/^$file$/,@array);
  2.  
to :

Expand|Select|Wrap|Line Numbers
  1. my @ee=grep(/^\Q$file\E$/,@array);
  2.  
In your case, $file contains forward slashes which will mess up the regex(as they stand for pattern delimiters). Even using double quotes and escaping the slashes will not work.
If you put a pattern between \Q and \E, any special meaning of the characters in pattern match will be ignored (variable substitutions will be allowed). For ex:
/\Q.*?\E/ will match '.*?'
Jun 2 '08 #3
rajiv07
141 100+
Change this line:
Expand|Select|Wrap|Line Numbers
  1. my @ee=grep(/^$file$/,@array);
  2.  
to :

Expand|Select|Wrap|Line Numbers
  1. my @ee=grep(/^\Q$file\E$/,@array);
  2.  
In your case, $file contains forward slashes which will mess up the regex(as they stand for pattern delimiters). Even using double quotes and escaping the slashes will not work.
If you put a pattern between \Q and \E, any special meaning of the characters in pattern match will be ignored (variable substitutions will be allowed). For ex:
/\Q.*?\E/ will match '.*?'
Thank You Nithin,

Why cannot we use escape the special regex char.its also working fine.Is any problem will occur when using this concept,if so please let me know and could u suggest any regexp site to refer.

Regards

Rajiv
Jun 2 '08 #4
nithinpes
410 Expert 256MB
Thank You Nithin,

Why cannot we use escape the special regex char.its also working fine.Is any problem will occur when using this concept,if so please let me know and could u suggest any regexp site to refer.

Regards

Rajiv
Sorry for the confusion and missed phrase. I mean to say: "Even using double quotes and escaping the slashes will not be a tidy work" (as it includes n number of slashes, dots & probably other characters).
So, instead of escaping each & every special characters, using \Q and \E would be crisp and easy.
Jun 2 '08 #5

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

Similar topics

6
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to...
8
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a...
4
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
4
by: henrik | last post by:
Hi I have a regex question. I want to find all content of a <td class="someclass"> tag. This means the expression should include all other tags included between <td class="someclass"> and </td>....
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
2
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to write a regular expression that will do the...
3
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a...
10
by: supercrossking | last post by:
I am trying to the values of string of text in the sample before. The ds are for digits and s is for string and string of text is for a string with more than one or two values. I am trying to use...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.