Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-13-2010, 08:25 AM   #1
LQ Newbie
Registered: Apr 2010
Posts: 29

Rep: Reputation: 0
Question Perl Scripting: Search for Regular Expression not work :(

I'm writing a Perl script to find an old key in a file and replace it with a new code
first the program should find the old key in the input file. here is the way I used in my script. but it doesn't work.
May you please let me know what is wrong and how I can correct it?
the key is stored in the file in the following format:
PHP Code:
Key=("1234567" someOtherVrable
I want 1234567
here is my script to find this key
open(INPUT,"inputfile.txt") or die "cant open file";
while (<INPUT> == NULL && $oldKey == NULL) {
$_=~ m/key\(\"(\S*)/ig;
if ($1 != NULL ){
print "The Old Key is  is $1";


Last edited by smc2; 10-13-2010 at 08:28 AM.
Old 10-13-2010, 09:19 AM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Looks like your regex should be more like
This should match any characters enclosed in quotes, and qualified by the leading 'Key=(' string. You could further qualify the match with trailing context, possibly including beginning-of-line and/or end-of-line anchors as well. If the key is always alphanumeric, you could replace the 'anything-not-a-quote' regex with '\d'.

--- rod.

Last edited by theNbomr; 10-13-2010 at 09:21 AM.


perlscript, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Regular Expression in VIM search and replace vijay_babu1981 Linux - Newbie 8 10-22-2009 08:49 AM
regular expression with perl MissEileen Programming 3 03-11-2008 02:26 PM
Perl Regular Expression abdul_zu Linux - Software 2 08-20-2007 04:57 AM
regular expression search/replace question (HELP!!! :) amytys Programming 5 09-06-2004 03:36 PM
Perl Regular Expression rch Programming 14 07-12-2003 12:00 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration