home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.20 / text0031.txt < prev    next >
Encoding:
Internet Message Format  |  1990-08-02  |  3.7 KB

  1. From:  Dominic Dunlop <domo@tsa.co.uk>
  2.  
  3. Note Followup-To: above.  Post elsewhere iff you think appropriate.
  4.  
  5. In article <1990Jun8.174056.15313@icc.com> wdm@icc.com (Bill Mulert) writes:
  6. : ... I would
  7. : like to have a tool, call it regex, that would allow me to say:
  8. : regex ' "^[^=]*=\(.*\)\" '
  9. : and have regex say, in plain language, what the expression means.
  10.  
  11. In article <8353@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV
  12. (Larry Wall) writes:
  13. >It's not likely to be too practical, for a couple of reasons.
  14. >
  15. >First, there a number of different standards out there.  For instance,
  16. >sed and expr use \( ... \) to indicate grouping, while egrep and perl
  17. >use ( ... ) for grouping, and \( and \) to indicate real parens...
  18.  
  19. We interrupt this posting for a word from our Sponsor Executive
  20. Committee.  But seriously, the 1003.2 working group for the Shell and
  21. Tools has at least documented the sh*t out of both ``Basic Regular
  22. Expressions'' (as in ed) and Extended Regular Expressions (egrep) (and
  23. perl, not that the thought of getting their claws (clauses?) into perl
  24. seems yet to have occired to standards people).  The result of 1003.2
  25. should be no obvious functional change in your favourite RE-using
  26. utility, but rather the clearing up of what should happen in any number
  27. of limiting cases around their edges.  (Actually, there are wide
  28. ranging and useful functional extensions, which add yet more
  29. hieroglyphic syntax: [=, =], [: and :] become special.  These
  30. character pairs were chosen so as to minimise the danger of breaking
  31. existing REs.)  The availability of a rigorous definition of REs and
  32. EREs should make easier the work of anybody who wants to write a RE to
  33. English translator.  (1003.2 could be considerably mor rigorous if it
  34. used formal techniques, but let's leave that for another year or few.)
  35.  
  36. >  On top of that, when are ?, +, |, { and } metacharacters?  They
  37. >are in some programs, and aren't in others.  Are you going to have a
  38. >switch?
  39. >
  40. >    regex -sed   ' "^[^=]*=\(.*\)\" ' # In 1003.2
  41. >    regex -expr  ' "^[^=]*=\(.*\)\" ' # In 1003.2
  42. >    regex -egrep ' "^[^=]*=\(.*\)\" ' # In 1003.2
  43. >    regex -ed    ' "^[^=]*=\(.*\)\" ' # In 1003.2
  44. >    regex -perl  ' "^[^=]*=\(.*\)\" ' # Not 1003.2 territory
  45. >    regex -emacs ' "^[^=]*=\(.*\)\" ' # Not 1003.2 territory
  46. >    regex -vi    ' "^[^=]*=\(.*\)\" ' # In 1003.2 User Portability
  47.                       #   Extension
  48.  
  49. Probably, even with 1003.2: the precise details of RE syntax vary between
  50. utilities, as those who worked on the standard usually opted in favour of
  51. documenting existing practice, even when the temptation to fix things was
  52. strong.  Of course, to conform to 1003.2's command line syntax rules, usage
  53. would have to be
  54.  
  55.     regex -t sed; regex -t expr      # or similar...
  56. >
  57. >Second, your big problem is not so much the regular expressions themselves
  58. >as it is all the quoting you have to put around them because of the paucity of
  59. >quoting mechanisms.  Take your first example:
  60. >
  61. >    echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
  62. >
  63. And so on, at rightly frustrated length.
  64.  
  65. One of several features which the 1003.2 definition of the shell lifts from
  66. the korn shell is the construct
  67.  
  68.     $(command)
  69.  
  70. as a preferred alternative to the now-deprecated
  71.  
  72.     `command`
  73.  
  74. (It's stuff like this which has vendors jumping up and down, complaining
  75. that they'll actually have to do some work before they can conform to the
  76. standard.)  The new construct does cut down on the number and depth of
  77. backslashes needed in... er... more interesting shell commands.  Although
  78. my fingers still fly for the backslashes, even though I normally use a
  79. korn shell...
  80.  
  81. >Unix is not a simple language.
  82.  
  83. I guess it's that way because it was designed to be easy for simple
  84. computers to understand.
  85. -- 
  86. Dominic Dunlop
  87.  
  88.  
  89. Volume-Number: Volume 20, Number 31
  90.  
  91.