Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 More Regular Expressions ...
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 08 April 2008 :  05:46:45  Show Profile
I've got the following RegExp running at the moment:
\[image=(.*?.(gif|jpeg|jpg|png)) align=(left|right) width=(\d+?) height=(\d+?) title=(.*?)\]
<img src="$1" class="$2" width="$3" height="$4" alt="$5" />
And it's working perfectly. The problem I'm facing though, is I need to make all the attributes optional so that if they're not included in the input string or don't have a value or, in the case of "align", the value isn't "left" or "right", the corresponding attribute is not included in the output string, except the "alt" attribute. Thinking about it, I can't see any way this would be possible with a regular expression, unless I created a separate pattern for each possible combination of attributes. Of course, I've been learning recently that advanced regular expressions are still way beyond my understanding!


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 08 April 2008 :  06:24:18  Show Profile  Send ruirib a Yahoo! Message
Yeah, I agree with you. If you want different outputs depending on the input, you'd need a different expression for each of the combinations. As an alternative, you'd need need some code to look at the matches and decide accordingly.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

MarcelG
Retired Support Moderator

Netherlands
2625 Posts

Posted - 09 April 2008 :  06:00:28  Show Profile  Visit MarcelG's Homepage
What I saw on Gathering of Tweakers (dutch tech forum), is that they do it like this (I have no idea how the RegExp behind this works, but this may give you a hint.):
[tagname=value1,value2] content [/tagname]
For example for the IMG tag, they have these values:
[img=width,height,link,align,title,border] url of the image[/img]
Now, to have an image with only the border turned on, you use this:
[img=,,,,,1] url of the image[/img]
To set it's dimensions, and provide a title but not set the border, use this:
[img=640,480,,,Image Title,] url of the image[/img]
It's pretty difficult for normal users to understand this method, but for the more advanced user it can be explained.

portfolio - linkshrinker - oxle - twitter

Edited by - MarcelG on 09 April 2008 06:02:05
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 09 April 2008 :  09:12:48  Show Profile  Visit HuwR's Homepage
how many attributes do you want to allow in your image tag ?

Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 09 April 2008 :  09:56:56  Show Profile
At most, it should only contain the 5 I posted above - image (src) align (class), width, height & title (alt). At least, it needs to contain the image (src) attribute. Here's the version I have at the moment, which allows for all possible combinations:
\[image=(\S*?.(gif|jpeg|jpg|png)) align=(left|right) width=(\d+?) height=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" class="$3" width="$4" height="$5"" alt="$7" />
\[image=(\S*?.(gif|jpeg|jpg|png))( title=(.*?)){0,1}\]
<img src="$1" alt="$4" />
\[image=(\S*?.(gif|jpeg|jpg|png)) width=(\d+?) height=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" width="$3" height="$4" alt="$6" />
\[image=(\S*?.(gif|jpeg|jpg|png)) align=(left|right)( title=(.*?)){0,1}\]
<img src="$1" class="$3" alt="$5" />
\[image=(\S*?.(gif|jpeg|jpg|png)) width=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" width="$3" alt="$5" />
\[image=(\S*?.(gif|jpeg|jpg|png)) height=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" height="$3" alt="$5" />
\[image=(\S*?.(gif|jpeg|jpg|png)) align=(left|right) width=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" class="$3" width="$4" alt="$6" />
\[image=(\S*?.(gif|jpeg|jpg|png)) align=(left|right) height=(\d+?)( title=(.*?)){0,1}\]
<img src="$1" class="$3" height="$4" alt="$6" />
Nice idea, Marcel; had started going down that route originally but, as you say, it's not exactly user friendly and it presents the same problem of how to exclude an attribute entirely from the output if it isn't assigned a value in the input.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 09 April 2008 :  10:16:29  Show Profile  Visit HuwR's Homepage
the basic problem you have is that the replace expression does not allow conditional replaces, so it can not know what to do if one of your variables is not in the initial string. the only way to do that would be to use the matches collection of the regexp object, however in classic ASP that is very limited
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 09 April 2008 :  10:20:19  Show Profile  Visit HuwR's Homepage
if you don't mind it not having "" round the attributes you could do something as simple as

\[image=(.*\.(gif|jpeg|jpg|png))\s+((height=(?:[\d]+\s*))|(width=(?:[\d]+\s*))|(title=(?:[^\s]+\s*))|(align=(?:[^\s]+\s*)))*]
<img src=$1 class=$2 $3 $4 $5 $6 $7/>
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2019 Snitz™ Communications Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000 Version 3.4.07