Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20584 > unrolled thread
| Started by | stach <mr.stachu@gmail.com> |
|---|---|
| First post | 2013-07-07 17:39 -0700 |
| Last post | 2013-07-08 04:22 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.javascript
need help for code rebuild stach <mr.stachu@gmail.com> - 2013-07-07 17:39 -0700
Re: need help for code rebuild JJ <duh@nah.meh> - 2013-07-08 08:33 +0700
Re: need help for code rebuild Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-08 04:22 +0200
| From | stach <mr.stachu@gmail.com> |
|---|---|
| Date | 2013-07-07 17:39 -0700 |
| Subject | need help for code rebuild |
| Message-ID | <1597f7ff-2002-4377-84e3-0b20de3365a8@googlegroups.com> |
Hi all user & dewelopers :)
i have code in js for find end replace word /make js-link/ in my site
this code working good - but need type exactly word for repalce
how to change this code for to change despite the different size of letters and link ended after finding space
my code:
function findARp(searchText, replacement, searchNode) {
if (!searchText || typeof replacement === 'undefined') {
return;
}
var regex = typeof searchText === 'string' ?
new RegExp(searchText, 'g') : searchText,
childNodes = (searchNode || document.getElementById('Blog1')).childNodes,
cnLength = childNodes.length,
excludes = 'html,head,style,title,link,meta,script,object,iframe,code,h1,h2,h3,img,form,textarea,a,audio,video';
while (cnLength--) {
var currentNode = childNodes[cnLength];
pops = currentNode.parentNode.className;
if (currentNode.nodeType === 1 &&
(excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
arguments.callee(searchText, replacement, currentNode);
}
if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
continue;
}
var parent = currentNode.parentNode,
frag = (function(){
var html = currentNode.data.replace(regex, replacement),
wrap = document.createElement('div'),
frag = document.createDocumentFragment();
wrap.innerHTML = html;
while (wrap.firstChild) {
frag.appendChild(wrap.firstChild);
}
return frag;
})();
parent.insertBefore(frag, currentNode);
parent.removeChild(currentNode);
}
}
findAndReplace('(na|mar|in|odio|amet|area)', '<a href="#">$1</a>');
this code find ex. odio in text and repalce for link <a href="#">odio</a>
if text is odioma link ended <a href="#">odio</a>ma i need <a href="#">odioma</a>
if text is Odio or odIoma code not working :(
currently resolve this problem using any occurrences of phrases ex.
findAndReplace('(odIo|odio|odioma|Odio)', '<b class="vink"><a href="#">$1</a></b>');
problem description & testpage http://tv-7.blogspot.com/2009/06/blog-post.html
thx
[toc] | [next] | [standalone]
| From | JJ <duh@nah.meh> |
|---|---|
| Date | 2013-07-08 08:33 +0700 |
| Message-ID | <m5plscgrg2ym$.1xv56byiz9jfo.dlg@40tude.net> |
| In reply to | #20584 |
On Sun, 7 Jul 2013 17:39:33 -0700 (PDT), stach wrote:
[snip]
> findAndReplace('(na|mar|in|odio|amet|area)', '<a href="#">$1</a>');
>
> this code find ex. odio in text and repalce for link <a href="#">odio</a>
>
> if text is odioma link ended <a href="#">odio</a>ma i need <a href="#">odioma</a>
> if text is Odio or odIoma code not working :(
>
> currently resolve this problem using any occurrences of phrases ex.
> findAndReplace('(odIo|odio|odioma|Odio)', '<b class="vink"><a href="#">$1</a></b>');
Simply add the "i" RegExp option for case-insensitive matching.
The RegExp creation code:
new RegExp(searchText, 'g')
Should become:
new RegExp(searchText, 'gi')
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-07-08 04:22 +0200 |
| Message-ID | <5207983.I3ivF7e9fM@PointedEars.de> |
| In reply to | #20584 |
stach wrote: > i have code in js for find end replace word /make js-link/ in my site ^ _I_ (always) > this code working good - but need type exactly word for repalce Of course. Do you *understand* the code in the first place? > how to change this code for to change despite the different size of > letters You mean different _length_ of _words_. > and link ended after finding space […] Possibility: Look before, and ahead. Get a real name. Do not use Google Groups for posting. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web