LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 06-13-2005, 01:57 PM   #1
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
Regular Expression Trivia


I am working on some SQL scripts which I'm translating and have come across a regexp pattern which works, but I don't know why.

The scene:
I am trying to remove double-qoutes (") from some sql scripts. An example sql line looks like

CREATE OR REPLACE PROCEDURE "proc_name"

I need to 'sed' this to

CREATE OR REPLACE PROCEDURE proc_name

simple enough. I'm not regexp cowboy so I was building my pattern and stumbled across this pattern which works though I don't know why.

sed -e 's/\(PROCEDURE[ ]\)*"/\1/g' sql-file

This produces
CREATE OR REPLACE PROCEDURE proc_name

though I don't know why, can anyone explain? Till then I am using the following pattern which works and I understand why.

sed -e 's/\(PROCEDURE[ ]*\)"\([A-Za-z0-9_]*\)"/\1\2/g' sql-file

-- jpbarto
 
Old 06-13-2005, 03:11 PM   #2
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
Hmmm,

Interessting thing, had me thinking for about 30 minutes, but...

It is actually quit easy (as allways)
This on works also, and is clearer why (for me it was)

Code:
sed -e 's/\(\)*"/\1/g'
It says, get everything unil " (if you can find it), and put it in "\1", then only output \1 without the "doubleticks" (gaensefueschen in german), then do it again.
(the g parameter at the end, say repeat until nothing is found anymore)

Nifty, I had not thought about solving something that easy.

Happy Hacking!
 
  


Reply



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
Need help with regular expression aecaudel Programming 6 11-04-2005 05:28 AM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 08:13 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 10:08 AM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM
regular expression gumby Programming 3 07-15-2003 12:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:00 PM.

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