Visit Our UNIX and Linux User Community


RegExp - settle a bet


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers RegExp - settle a bet
# 1  
Old 04-17-2008
RegExp - settle a bet

A couple co-workers have a disagreement. Can you guys please settle this?

One co-worker says regular expressions can inherently search and replace. His argument is that he can do a s/ regexp / replace in perl (and many other languages).

The other says that by definition regular expressions is just pattern matching and that is an outside function doing the replacing.

Thoughts?
# 2  
Old 04-17-2008
Quote:
Originally Posted by earnstaf
A couple co-workers have a disagreement. Can you guys please settle this?

One co-worker says regular expressions can inherently search and replace. His argument is that he can do a s/ regexp / replace in perl (and many other languages).

The other says that by definition regular expressions is just pattern matching and that is an outside function doing the replacing.

Thoughts?
Regular Expressions are just patterns...They do not perform any functions...It is the commands like sed or tr that we use along with the regular expression performs the functions like substitute/translate the pattern matched.

Its just my thought!
# 3  
Old 04-17-2008
Concur, the substitution facility is not part of the regular expression formalism proper.

The original implementation of regular expressions was by Ken Thompson in the QED (and later ed) editor. Certainly, there was the s/re/p command in that already then, but his paper on regular expressions describes the "search" part and the underlying mathematical formalism, a concept called "regular sets" which is where the "regular" part in the name comes from.

Ken Thompson - Wikipedia, the free encyclopedia
Regular expression - Wikipedia, the free encyclopedia

K. Thompson, Regular Expression Search Algorithm, Comm. Assoc. Comp. Mach., Vol. 11, 6, pp. 419--422, 1968.

(It's the very first article in his publications list at http://www.cs.bell-labs.com/cm/cs/bib2html/ken.htm)
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #391
Difficulty: Medium
Darwin, the open source subset of macOS, has behavior that can be set to comply with UNIX 03.
True or False?

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find diff bet 2 files and store result in another file

Hi I want to compare 2 files. The files have the same amount of rows and columns. So each line must be compare against the other and if one differs from the other, the result of both must be stored in a seperate file. I am doing this in awk. Here is my file1: Blocks... (2 Replies)
Discussion started by: ladyAnne
2 Replies

2. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

3. Shell Programming and Scripting

script to read a line with spaces bet " " and write to a file

Hi, I need a command in UNIX KSH below is the description... MAPPING DESCRIPTION ="Test Mapping for the calid inputs" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1" unix ksh command to read the DESCRIPTION and write to a file Test Mapping for the calid inputs... (3 Replies)
Discussion started by: perlamohan
3 Replies

4. Programming

how to run prog bet to break points

Hi, I have set two break points at 500 and 572 lines respectively. after running prog using (gdb) run i m on the line 500 but how two go to second breakpoints ie line 572 . when i m giving (gdb) run it is asking again to run from starting lines . (1 Reply)
Discussion started by: useless79
1 Replies

5. News, Links, Events and Announcements

Microsoft and Sun Settle Litigation

http://www.microsoft.com/presspass/press/2004/apr04/04-02SunAgreementPR.asp no comments sad pressy (1 Reply)
Discussion started by: pressy
1 Replies

6. UNIX for Dummies Questions & Answers

No 5 fail. When install Patches. How to settle?

Install 2.6Recommanded on 2 workstations, one works, but the other one has many No 5 fail. the log says: Installing 106361-14... WARNING: /usr/sbin/patchadd is being used to install this patch. Checking installed packages and patches... Executing prepatch script... Verifying... (1 Reply)
Discussion started by: cloudsmell
1 Replies

Featured Tech Videos