regextr 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # usage: regextr [exp]*
  3. #
  4. # eg:
  5. # capt=(
  6. # /capt=)
  7. # etc.
  8. #
  9. # see your ~/.regextr for the complete syntax, or the code just below
  10. #
  11. # it can be used yet to compose expressions:
  12. #
  13. # echo lol | pcregrep "`./regextr capt captname text /captname l repeated /capt`"
  14. #
  15. if [ "X$0" = "X" ]; then
  16. echo "usage: regextr [exp]*"
  17. exit
  18. fi
  19. if [ ! -e ~/.regextr ]; then
  20. # creating default syntax file..
  21. echo "exp=/" >>~/.regextr
  22. echo "/exp=/" >>~/.regextr
  23. echo "boundstart=^" >>~/.regextr
  24. echo "boundend=$" >>~/.regextr
  25. echo "capt=(" >>~/.regextr
  26. echo "/capt=)" >>~/.regextr
  27. echo "captor=|" >>~/.regextr
  28. echo "captname=?<" >>~/.regextr
  29. echo "/captname=>" >>~/.regextr
  30. echo "range=[" >>~/.regextr
  31. echo "notrange=[^" >>~/.regextr
  32. echo "/range=]" >>~/.regextr
  33. echo "digit=\d" >>~/.regextr
  34. echo "string=." >>~/.regextr
  35. echo "word=\w" >>~/.regextr
  36. echo "space=\s" >>~/.regextr
  37. echo "notspace=\S" >>~/.regextr
  38. echo "repeated=+" >>~/.regextr
  39. echo "maybenot=?" >>~/.regextr
  40. echo "quant={" >>~/.regextr
  41. echo "quantsep=-" >>~/.regextr
  42. echo "/quant=}" >>~/.regextr
  43. fi
  44. res=""
  45. for exp in $@; do
  46. test=`pcregrep ^$exp\= ~/.regextr | cut -d = -s -f 2`
  47. if [ "X$test" = "X" ]; then
  48. res=$res$exp
  49. else
  50. res=$res`pcregrep ^$exp\= ~/.regextr | cut -d = -s -f 2`
  51. fi
  52. done
  53. echo $res