• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 951
  • Last Modified:

var rightText = RegExp.$3 - Need leftText

Hello All;

In my site that Hielo helped me in.
It is JavaScript based, and this function

var rightText = RegExp.$3

case '[url': 
var temp=attributes.split('|');
return '<a href="'+temp[0]+'" title="'+temp[1]+'" target="_blank" rel="nofollow">'+temp[1]+'</a>&#171;'+rightText;

Open in new window


Of which allows for text on the right side.
I need it to allow text on the left as well.

Basically.

hello, this is a link [url:www.example.com|Example] that you can click on.

Right now, it will not display as a link, as there is text on the left side,  it will only display the actually code.
So, what I am needing, is the leftText to be added in.

Any help on this will be great.
Carrzkiss
0
Wayne Barron
Asked:
Wayne Barron
  • 4
  • 3
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Here it is in vbs

<%
str="hello, this is a link [url:www.example.com|Example] that you can click on."
leftside=mid(str,instr(1,str,"www",1),instr(1,str,"|",1)-instr(1,str,"www",1) )
rightside=mid(str,instr(1,str,"|",1)+1,instr(1,str,"]",1)-1-instr(1,str,"|",1) )
response.write leftside
response.write "|"&rightside
%>

Open in new window

0
 
hieloCommented:
If I remember correctly, there were two functions:
process and bbFilter.  You need to call proccess passing bbFilter as the the second argument:
Response.Write( process(inputStr, bbFilter) )

Open in new window


It sounds like you are simply calling it as:
Response.Write( process(inputStr) )

Open in new window

0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Hielo.
I am doing it as the 1st one, exactly.
It has been like that since the code was first done.

padas, the whole page is done in JavaScript, I will be unable to change it to vbscript.
Though that is my comfort zone, I cannot change it now.
Maybe in the future, I can look at a possible convert.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Also, to Hielo.
If I do the [[info|Information Here]]
This works no matter where it is located at, in the middle of text, before, after, works perfectly.

It is only the code like what I supplied above, that does not work in the middle, or the end, only the beginning.
0
 
hieloCommented:
Can you provide a sample input string?
0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
As sample is as I provided above.
Check out [url:www.eperts-exchange.com|Eperts Exchange] for your project needs and help

It does not matter rather there is 1 or many url's on the same line of not, they will not work if there is text on the "LEFT" side of the tag.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Very similar in js http://jsfiddle.net/ECxXF/

var str = "hello, this is a link [url:www.example.com|Example] that you can click on.";

var left1=str.indexOf('[')+5;
var left2=str.indexOf('|');
var right1=str.indexOf('|')+1;
var right2=str.indexOf(']');

document.write  (str.substring(left1,left2));
document.write ("<br>");
document.write  (str.substring(right1,right2));

Open in new window

0
 
hieloCommented:
@padas:  This question is a follow-up to request he submitted more than a year ago.  You are on the right track.  However, the input string he is dealing with may have multiple instances of "[url:xxxx|yyyy]".

@carrzkiss: try putting the following patch at the beginning of the function:
function process(str, filter){
	//if no input was provided, return empty string
	str = typeof(str)=='undefined' ? '' : str;
	if(!str) return '';

	var result=str.match(/(\[url:[^\]]+\])/ig);
	
	if( result ) 
	{
		for(var i=0,limit=result.length; i<limit;++i)
		{
			var temp=result[i].substring(5,result[i].length-1).split('|');
			temp[0]=temp[0].replace(/^\s+|\s+$/g,'');

			if(temp.length>1)
			{
				temp[1]=temp[1].replace(/^\s+|\s+$/g,'');
			}

			if( !/^(f|ht)tps?:/i.test(temp[0]))
			{
				temp[0]='http://'+temp[0];
			}

			if( temp.length==2 )
			{
				str=str.replace(result[i],'<a href="'+temp[0]+'" title="'+temp[1]+'">'+temp[1]+'</a>');
			}
			else
			{
				str=str.replace(result[i],'<a href="'+temp[0]+'" >'+temp[0].replace(/^https?:../i,'')+'</a>');
			}
		}
	}

	//make sure there exists a filter always. If not is specified, then the default
...
}

Open in new window

0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Just tested it in the demo page, and now on my working testing server,
And it works like a champ.

Thanks a bunch Hielo!!
You Rock!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now