all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Regular expression - replace lower case to upper case
  2002-11-01  4:33 Regular expression - replace lower case to upper case Rod Farmer
@ 2002-11-01  2:32 ` Michael Slass
  2002-11-01 19:34   ` Reiner Steib
  2002-11-01  2:33 ` David Forrest
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Slass @ 2002-11-01  2:32 UTC (permalink / raw)


"Rod Farmer" <raf@cs.mu.oz.au> writes:

>Hi,
>    I've been looking through the manuals and can't seem to find how to
>replace all occurences of HTML tags in lower case, ie <body> with upper case
><BODY> as seems to be the W3C standards for 4.01
>
>I was going to use M-x % regexp RET string RET but what I really want is
>something like the s/foo/bar/g where
>bar can actually be a reference back to the string that has been
>matched.....
>
>
>thanks heaps
>
>
>Rod
>
>

Try this:

(defun upcase-html-tags (buf)
 (interactive "*bUpcase html tags in buffer: ")
  (save-excursion
    (set-buffer buf)
    (goto-char (point-min))
    (let ((counter 0))
      (while (re-search-forward "<\\(\\w+\\)>" nil t)
        (upcase-region (match-beginning 1) (match-end 1))
        (setq counter (1+ counter)))
      (message "upcased %d html tags" counter)))) 

-- 
Mike Slass

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression - replace lower case to upper case
  2002-11-01  4:33 Regular expression - replace lower case to upper case Rod Farmer
  2002-11-01  2:32 ` Michael Slass
@ 2002-11-01  2:33 ` David Forrest
  1 sibling, 0 replies; 5+ messages in thread
From: David Forrest @ 2002-11-01  2:33 UTC (permalink / raw)


On Fri, 1 Nov 2002, Rod Farmer wrote:

> Hi,
>     I've been looking through the manuals and can't seem to find how to
> replace all occurences of HTML tags in lower case, ie <body> with upper case
> <BODY> as seems to be the W3C standards for 4.01
>
> I was going to use M-x % regexp RET string RET but what I really want is
> something like the s/foo/bar/g where
> bar can actually be a reference back to the string that has been
> matched.....

Well, you will probably need to write a function.  regexps CAN refer back
to parts of the matched string  (using \(html|body\) in the search part,
and \1 in the replace part), but they won't be able to uppercase it.

Dave
-- 
 Dave Forrest    (434)924-3954w(111B) (804)642-0662h (804)695-2026p
 drf5n@virginia.edu             http://mug.sys.virginia.edu/~drf5n/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Regular expression - replace lower case to upper case
@ 2002-11-01  4:33 Rod Farmer
  2002-11-01  2:32 ` Michael Slass
  2002-11-01  2:33 ` David Forrest
  0 siblings, 2 replies; 5+ messages in thread
From: Rod Farmer @ 2002-11-01  4:33 UTC (permalink / raw)


Hi,
    I've been looking through the manuals and can't seem to find how to
replace all occurences of HTML tags in lower case, ie <body> with upper case
<BODY> as seems to be the W3C standards for 4.01

I was going to use M-x % regexp RET string RET but what I really want is
something like the s/foo/bar/g where
bar can actually be a reference back to the string that has been
matched.....


thanks heaps


Rod

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression - replace lower case to upper case
  2002-11-01  2:32 ` Michael Slass
@ 2002-11-01 19:34   ` Reiner Steib
  2002-11-01 21:49     ` Michael Slass
  0 siblings, 1 reply; 5+ messages in thread
From: Reiner Steib @ 2002-11-01 19:34 UTC (permalink / raw)


On Fri, Nov 01 2002, Michael Slass wrote:

> Try this:
>
> (defun upcase-html-tags (buf)
>  (interactive "*bUpcase html tags in buffer: ")
[...]
>       (message "upcased %d html tags" counter)))) 

Nice. I changed your function slighly: include closing tags (</foo>),
always use current buffer. Because I prefer lowercase tags, you need
do give a prefix argument, if you want uppercase tags:

M-x rs-html-downcase-or-upcase-tags RET     --> downcase buffer
C-u M-x rs-html-downcase-or-upcase-tags RET --> upcase buffer

(defun rs-html-downcase-or-upcase-tags (&optional upcase)
  "Downcase html-tags in curent buffer.  If given a prefix, upcase tags."
  (interactive "P")
  (save-excursion
    (goto-char (point-min))
    (let ((counter 0))
      (while (re-search-forward "</?\\(\\w+\\)>" nil t)
	(funcall
	 (if upcase 'upcase-region 'downcase-region)
	 (match-beginning 1) (match-end 1))
	(setq counter (1+ counter)))
      (message "%scased %d html-tags" (if upcase "up" "down") counter))))

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo--- PGP key available via WWW   http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Regular expression - replace lower case to upper case
  2002-11-01 19:34   ` Reiner Steib
@ 2002-11-01 21:49     ` Michael Slass
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Slass @ 2002-11-01 21:49 UTC (permalink / raw)


Reiner Steib <4uce.02.r.steib@gmx.net> writes:

>Nice. I changed your function slighly: include closing tags (</foo>),
>always use current buffer. Because I prefer lowercase tags, you need
>do give a prefix argument, if you want uppercase tags:
>
>M-x rs-html-downcase-or-upcase-tags RET     --> downcase buffer
>C-u M-x rs-html-downcase-or-upcase-tags RET --> upcase buffer
>

That's even better -- the beauty of free software, you can season it
to taste.

Regards,
-- 
Mike Slass

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-11-01 21:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-01  4:33 Regular expression - replace lower case to upper case Rod Farmer
2002-11-01  2:32 ` Michael Slass
2002-11-01 19:34   ` Reiner Steib
2002-11-01 21:49     ` Michael Slass
2002-11-01  2:33 ` David Forrest

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.