Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Regular Expression Help please!

Reply
Thread Tools

Regular Expression Help please!

 
 
Giles
Guest
Posts: n/a
 
      11-01-2009
My (VB/ASP) site parses pseudocode created by authors. For example, the
author's HTML might contain
[start small padded box] This content displays in a box [end small padded
box]
The bits in square brackets are then replaced with appropriate HTML to
create a border around the text.

PageHTML=replace(PageHTML,"[start small padded box]","<div
style='width:200px; padding:4px; border:1px solid #000'>")
PageHTML=replace(PageHTML,"[end small padded box]","</div>")

The problem is, the spaces might (or might not) be &nbsp; due to the
authoring interface
[start small&nbsp;padded box] This content displays in a box [end&nbsp;small
padded&nbsp;box]

Is there a regular expression that can turn &nbsp; (if they exist) into
spaces? (Prior to applying the pseudocode conversion)

function deNBSP(s,html)
?
?
end function
PageHTML=deNBSP("[start small padded box]", PageHTML)
PageHTML=deNBSP("[end small padded box]", PageHTML)

The pseudocode phrases can be quite long, and have a lot of spaces, I was
hoping a RegExp would be quicker than looping through, using replace() for
every permutation of space - &nbsp; in a phrase.

Thanks if you can help, or advise a different strategy.


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      11-01-2009
Giles wrote:

> The problem is, the spaces might (or might not) be &nbsp; due to the
> authoring interface
> [start small&nbsp;padded box] This content displays in a box
> [end&nbsp;small padded&nbsp;box]
>
> Is there a regular expression that can turn &nbsp; (if they exist)
> into spaces? (Prior to applying the pseudocode conversion)
>

..

A simple call to Replace should do this - no need for regex.
s = Replace(s,"&nbsp;", " ")

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
 
Giles
Guest
Posts: n/a
 
      11-01-2009
> Giles wrote:
>
>> The problem is, the spaces might (or might not) be &nbsp; due to the
>> authoring interface
>> [start small&nbsp;padded box] This content displays in a box
>> [end&nbsp;small padded&nbsp;box]
>>
>> Is there a regular expression that can turn &nbsp; (if they exist)
>> into spaces? (Prior to applying the pseudocode conversion)

> .
> Bob Barrows wrote:
>
> A simple call to Replace should do this - no need for regex.
> s = Replace(s,"&nbsp;", " ")


Thanks Bob, but that would change all the nbsp's in the PageHTML, not just
the ones in the pseudocode phrases. The page may contain other necessary
nbsp's. It's the pseudocode phrase that varies:
I am trying to find a way around doing -
PageHTML=replace(PageHTML,"[start&nbsp;small padded box]","[start small
padded box]")
PageHTML=replace(PageHTML,"[start small&nbsp;padded box]","[start small
padded box]")
PageHTML=replace(PageHTML,"[start small padded&nbsp;box]","[start small
padded box]")
PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded box]","[start small
padded box]")
PageHTML=replace(PageHTML,"[start small&nbsp;padded&nbsp;box]","[start small
padded box]")
PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded&nbsp;box]","[start
small padded box]")


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      11-01-2009
Giles wrote:
>> Giles wrote:
>>
>>> The problem is, the spaces might (or might not) be &nbsp; due to the
>>> authoring interface
>>> [start small&nbsp;padded box] This content displays in a box
>>> [end&nbsp;small padded&nbsp;box]
>>>
>>> Is there a regular expression that can turn &nbsp; (if they exist)
>>> into spaces? (Prior to applying the pseudocode conversion)

>> .
>> Bob Barrows wrote:
>>
>> A simple call to Replace should do this - no need for regex.
>> s = Replace(s,"&nbsp;", " ")

>
> Thanks Bob, but that would change all the nbsp's in the PageHTML, not
> just the ones in the pseudocode phrases. The page may contain other
> necessary nbsp's. It's the pseudocode phrase that varies:
> I am trying to find a way around doing -
> PageHTML=replace(PageHTML,"[start&nbsp;small padded box]","[start
> small padded box]")
> PageHTML=replace(PageHTML,"[start small&nbsp;padded box]","[start
> small padded box]")
> PageHTML=replace(PageHTML,"[start small padded&nbsp;box]","[start
> small padded box]")
> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded
> box]","[start small padded box]")
> PageHTML=replace(PageHTML,"[start
> small&nbsp;padded&nbsp;box]","[start small padded box]")
> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded&nbsp;box]","[start
> small padded box]")


Then you will need regex. Unfortunately, I'm not fluent in regular
expressions so all I can do is suggest you go to the documentation.
Hopefully someone else will jump in and help you out.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      11-01-2009
Bob Barrows wrote on 01 nov 2009 in
microsoft.public.inetserver.asp.general:

> Giles wrote:
>>> Giles wrote:
>>>
>>>> The problem is, the spaces might (or might not) be &nbsp; due to
>>>> the authoring interface
>>>> [start small&nbsp;padded box] This content displays in a box
>>>> [end&nbsp;small padded&nbsp;box]
>>>>
>>>> Is there a regular expression that can turn &nbsp; (if they exist)
>>>> into spaces? (Prior to applying the pseudocode conversion)
>>> .
>>> Bob Barrows wrote:
>>>
>>> A simple call to Replace should do this - no need for regex.
>>> s = Replace(s,"&nbsp;", " ")

>>
>> Thanks Bob, but that would change all the nbsp's in the PageHTML, not
>> just the ones in the pseudocode phrases. The page may contain other
>> necessary nbsp's. It's the pseudocode phrase that varies:
>> I am trying to find a way around doing -
>> PageHTML=replace(PageHTML,"[start&nbsp;small padded box]","[start
>> small padded box]")
>> PageHTML=replace(PageHTML,"[start small&nbsp;padded box]","[start
>> small padded box]")
>> PageHTML=replace(PageHTML,"[start small padded&nbsp;box]","[start
>> small padded box]")
>> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded
>> box]","[start small padded box]")
>> PageHTML=replace(PageHTML,"[start
>> small&nbsp;padded&nbsp;box]","[start small padded box]")
>> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded&nbsp;box]","[
>> start small padded box]")

>
> Then you will need regex. Unfortunately, I'm not fluent in regular
> expressions so all I can do is suggest you go to the documentation.
> Hopefully someone else will jump in and help you out.


Perhaps I can help you out with Regex,
but I do not know what you mean by "pseudocode phrases".

Let us just define a string called PageHTML [i am not interested in the
final purpose], I suppose pars of that string with well defined start and
ends need to be purged of a certain substring.

Please define the start and end of such substrings.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Giles
Guest
Posts: n/a
 
      11-01-2009

"Evertjan." <(E-Mail Removed)> wrote in message
news:Xns9CB6D34ED8CC4eejj99@194.109.133.242...
> Bob Barrows wrote on 01 nov 2009 in
> microsoft.public.inetserver.asp.general:
>
>> Giles wrote:
>>>> Giles wrote:
>>>>
>>>>> The problem is, the spaces might (or might not) be &nbsp; due to
>>>>> the authoring interface
>>>>> [start small&nbsp;padded box] This content displays in a box
>>>>> [end&nbsp;small padded&nbsp;box]
>>>>>
>>>>> Is there a regular expression that can turn &nbsp; (if they exist)
>>>>> into spaces? (Prior to applying the pseudocode conversion)
>>>> .
>>>> Bob Barrows wrote:
>>>>
>>>> A simple call to Replace should do this - no need for regex.
>>>> s = Replace(s,"&nbsp;", " ")
>>>
>>> Thanks Bob, but that would change all the nbsp's in the PageHTML, not
>>> just the ones in the pseudocode phrases. The page may contain other
>>> necessary nbsp's. It's the pseudocode phrase that varies:
>>> I am trying to find a way around doing -
>>> PageHTML=replace(PageHTML,"[start&nbsp;small padded box]","[start
>>> small padded box]")
>>> PageHTML=replace(PageHTML,"[start small&nbsp;padded box]","[start
>>> small padded box]")
>>> PageHTML=replace(PageHTML,"[start small padded&nbsp;box]","[start
>>> small padded box]")
>>> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded
>>> box]","[start small padded box]")
>>> PageHTML=replace(PageHTML,"[start
>>> small&nbsp;padded&nbsp;box]","[start small padded box]")
>>> PageHTML=replace(PageHTML,"[start&nbsp;small&nbsp;padded&nbsp;box]","[
>>> start small padded box]")

>>
>> Then you will need regex. Unfortunately, I'm not fluent in regular
>> expressions so all I can do is suggest you go to the documentation.
>> Hopefully someone else will jump in and help you out.

>
> Perhaps I can help you out with Regex,
> but I do not know what you mean by "pseudocode phrases".
>
> Let us just define a string called PageHTML [i am not interested in the
> final purpose], I suppose pars of that string with well defined start and
> ends need to be purged of a certain substring.
>
> Please define the start and end of such substrings.
> --
> Evertjan.


Thank you Evertjan
Each pseudocode phrase is a sub-string within PageHTML that starts with
Open-Square-Bracket [, and ends with Close-Square-Bracket, ].
It can contain any number of words, separated by spaces.
Some of the "spaces" might be &nbsp;
It needs to be purged of &nbsp; each occurrence being replaced by a space.

e.g.
[word1 word2 word3 word4] - is OK
[word1&nbsp;word2] - needs converting to [word1 word2]

Examples are
[podcast lecture.mp3]

[movie /flv/demo.flv width=400 height=300]

<b>Quiz</b><br />
[mcq start]
Questions here...
[mcq end]













 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      11-01-2009
Giles wrote on 01 nov 2009 in microsoft.public.inetserver.asp.general:

> Thank you Evertjan
> Each pseudocode phrase is a sub-string within PageHTML that starts
> with Open-Square-Bracket [, and ends with Close-Square-Bracket, ].
> It can contain any number of words, separated by spaces.
> Some of the "spaces" might be &nbsp;
> It needs to be purged of &nbsp; each occurrence being replaced by a
> space.


Could be done like this,
I use a Javascript function for simplicity:

==============================================
<% 'vbs

PageHTML = "[word1 word2 word3 word4]z&nbsp;z" &_
"[word5&nbsp;word6]z&nbsp;z" &_
"[word7&nbsp;word8&nbsp;word9]"

PageHTML = replaceNbsp(PageHTML)

Response.write PageHTML

%>

<script language='javascript' runat='server'>
function replaceNbsp(s) {
return s.replace(/(\[.*?\])/g,function(a)
{return a.replace(/&nbsp;/g,' ');});
};
</script>
==============================================

You will need view-source to see that the &nbsp;
outside the [...] are not touched.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Giles
Guest
Posts: n/a
 
      11-02-2009
> Giles wrote on 01 nov 2009 in microsoft.public.inetserver.asp.general:
>
>> Thank you Evertjan
>> Each pseudocode phrase is a sub-string within PageHTML that starts
>> with Open-Square-Bracket [, and ends with Close-Square-Bracket, ].
>> It can contain any number of words, separated by spaces.
>> Some of the "spaces" might be &nbsp;
>> It needs to be purged of &nbsp; each occurrence being replaced by a
>> space.

>
> Could be done like this,
> I use a Javascript function for simplicity:
>
> ==============================================
> <% 'vbs
>
> PageHTML = "[word1 word2 word3 word4]z&nbsp;z" &_
> "[word5&nbsp;word6]z&nbsp;z" &_
> "[word7&nbsp;word8&nbsp;word9]"
>
> PageHTML = replaceNbsp(PageHTML)
>
> Response.write PageHTML
>
> %>
>
> <script language='javascript' runat='server'>
> function replaceNbsp(s) {
> return s.replace(/(\[.*?\])/g,function(a)
> {return a.replace(/&nbsp;/g,' ');});
> };
> </script>
> ==============================================
>
> You will need view-source to see that the &nbsp;
> outside the [...] are not touched.
>
> --
> Evertjan.


Perfect. Your help is very much appreciated, thank you Evertjan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments