Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] regexp - replace & capture with one operation?
- From: paul at novitskisoftware.com (Paul Novitski)
- Subject: [Javascript] regexp - replace & capture with one operation?
- Date: Thu May 19 14:39:01 2005
Here's my regexp question:
1) I want to transform this source text:
"This text contains {ix_key|index terms} to be processed."
...into this:
"This text contains <a class="ix_key" href="#ix_key">index terms</a> to be
processed."
The key becomes the class and the local anchor link, and the term becomes
embedded in the anchor tag.
My first stab at a regexp would be:
.replace(/\{(.)*\|(.)*\}/, "<a class="$1" href="#$1">$2</a>")
2) I also want to collect each key (e.g., "ix_key") for further
processing. If performed separately, I figure the regexp for this would be:
.match(/\{(.)*\|.*\}/)
to generate an array of keys or key locations.
Do I have to do this with two regexp operations, one to locate & "capture"
the keys and another to mark up the keys and terms with HTML?
Thanks,
Paul
- Follow-Ups:
- [Javascript] regexp - replace & capture with one operation?
- From: Shawn Milo
- [Javascript] regexp - replace & capture with one operation?
- Prev by Date: [Javascript] RegEx for validating a file name
- Next by Date: [Javascript] regexp - replace & capture with one operation?
- Previous by thread: [Javascript] NETSCAPE 7.0 (DISABLE CONTROL-CLICK on LINKS)
- Next by thread: [Javascript] regexp - replace & capture with one operation?
- Index(es):