home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 14914 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  1.9 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!comlab.ox.ac.uk!mbeattie
  2. From: mbeattie@black.ox.ac.uk (Malcolm Beattie)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: A simple question about lex!
  5. Message-ID: <1992Dec23.104418.27174@black.ox.ac.uk>
  6. Date: 23 Dec 92 10:44:18 GMT
  7. References: <1h7i58INNms4@function.mps.ohio-state.edu>
  8. Organization: Oxford University Computing Service, 13 Banbury Rd, Oxford, U
  9. Lines: 53
  10. Originator: mbeattie@black
  11.  
  12. In article <1h7i58INNms4@function.mps.ohio-state.edu> ren@function.mps.ohio-state.edu (Liming Ren) writes:
  13. >This is the first time I am using lex. I am puzzled by the following problem;
  14. >
  15. >I want to match 
  16. >beginning of line  .I followed by one or more space ,then a number and then 
  17. >newline. For example
  18. >.I  123\n
  19. >.I   234\n
  20. >
  21. >
  22. >I tested  ^\.I[ ]+ [0-9]+$ , ^\.I[ ]+[0-9]+$  and ^\.I [ ]+ [0-9]+$,
  23. > none of them  works!
  24. >
  25. >I tried    ^\.I" "[0-9]+$  , it works only for patten with one space in between.
  26. >Please help me to find the correct specification.
  27. >
  28. >
  29. >Many thanks!
  30.  
  31. The following works for me (DEC5500, Ultrix 4.2A).
  32. Notice that your `$' finds the number at end-of-line but
  33. doesn't swallow the \n---that gets passed in as the next character.
  34.  
  35. [~/src]black% cat foo.l
  36. %%
  37. ^\.I[ ]+[0-9]+$ { puts("Found .I line"); }
  38. [~/src]black% lex foo.l
  39. [~/src]black% cc lex.yy.c -ll
  40. [~/src]black% 
  41. [~/src]black% cat fooin
  42. The quick brown fox
  43. .I 1234
  44. .I     567
  45. .I blah
  46. is getting tired of jumping
  47. [~/src]black% ./a.out < fooin > fooout
  48. [~/src]black% cat fooout
  49. The quick brown fox
  50. Found .I line
  51.  
  52. Found .I line
  53.  
  54. .I blah
  55. is getting tired of jumping
  56. [~/src]black% 
  57.  
  58. --Malcolm
  59.  
  60. -- 
  61. Malcolm Beattie <mbeattie@black.ox.ac.uk> | I'm not a kernel hacker
  62. Oxford University Computing Services      | I'm a kernel hacker's mate
  63. 13 Banbury Road, Oxford, OX2 6NN (U.K.)   | And I'm only hacking kernels
  64. Tel: +44 865 273232 Fax: +44 865 273275   | 'Cos the kernel hacker's late
  65.