Regular expression question 
Author Message
 Regular expression question

I'm trying to match the <script> ... </script> in the following HTML text
using a regular expression:
<script language="vbscr>ipt" for="idDoit" event="onclick">
Dim re, Match, Matches, s, m

  Set re = new RegExp

  re.Pattern = idPattern.value
  re.Global = true
  re.IgnoreCase = true

  s = idInput.value
  m = ""

  Set Matches = re.Execute(s)
  for each Match in Matches
   m = m & Match.Value & vbCrLf
  next

  idOutput.innerText = m
</script>

and using the pattern:

<.?script.*>[.\s]*

As far as my knowledge of regexps goes, that pattern should match everything
after the first line right up to and including the last line.

However, the pattern actually only matches as follows (starting position is
indicated):
_________________________________________________
0: <script language="vbscr>ipt" for="idDoit" event="onclick">

357: </script>
_________________________________________________

My question is: how can I match opening and closing HTML tags and their
content when spread across lines in a string?

TIA

John O'Connell



Mon, 16 Jun 2003 23:44:55 GMT  
 Regular expression question
  <.?script.*>[.\s]*
              ^^^^^^
This is looking for 0 or more occurrences of periods or whitespace
characters. "." isn't a wildcard in a character set.

You probably want to use a lazy match and explicitly look for the closing
tag.

  <script.*?>[\S\s]*?</script>

=-=-=
Steve
-=-=-


Quote:
> I'm trying to match the <script> ... </script> in the following HTML text
> using a regular expression:
> <script language="vbscr>ipt" for="idDoit" event="onclick">
> Dim re, Match, Matches, s, m

>   Set re = new RegExp

>   re.Pattern = idPattern.value
>   re.Global = true
>   re.IgnoreCase = true

>   s = idInput.value
>   m = ""

>   Set Matches = re.Execute(s)
>   for each Match in Matches
>    m = m & Match.Value & vbCrLf
>   next

>   idOutput.innerText = m
> </script>

> and using the pattern:

> <.?script.*>[.\s]*

> As far as my knowledge of regexps goes, that pattern should match
everything
> after the first line right up to and including the last line.

> However, the pattern actually only matches as follows (starting position
is
> indicated):
> _________________________________________________
> 0: <script language="vbscr>ipt" for="idDoit" event="onclick">

> 357: </script>
> _________________________________________________

> My question is: how can I match opening and closing HTML tags and their
> content when spread across lines in a string?

> TIA

> John O'Connell



Wed, 18 Jun 2003 01:46:23 GMT  
 Regular expression question
Ah of course ... I ended up using the exact solution you've just presented.

thanx

John


Quote:
>   <.?script.*>[.\s]*
>               ^^^^^^
> This is looking for 0 or more occurrences of periods or whitespace
> characters. "." isn't a wildcard in a character set.

> You probably want to use a lazy match and explicitly look for the closing
> tag.

>   <script.*?>[\S\s]*?</script>

> =-=-=
> Steve
> -=-=-



> > I'm trying to match the <script> ... </script> in the following HTML
text
> > using a regular expression:
> > <script language="vbscr>ipt" for="idDoit" event="onclick">
> > Dim re, Match, Matches, s, m

> >   Set re = new RegExp

> >   re.Pattern = idPattern.value
> >   re.Global = true
> >   re.IgnoreCase = true

> >   s = idInput.value
> >   m = ""

> >   Set Matches = re.Execute(s)
> >   for each Match in Matches
> >    m = m & Match.Value & vbCrLf
> >   next

> >   idOutput.innerText = m
> > </script>

> > and using the pattern:

> > <.?script.*>[.\s]*

> > As far as my knowledge of regexps goes, that pattern should match
> everything
> > after the first line right up to and including the last line.

> > However, the pattern actually only matches as follows (starting position
> is
> > indicated):
> > _________________________________________________
> > 0: <script language="vbscr>ipt" for="idDoit" event="onclick">

> > 357: </script>
> > _________________________________________________

> > My question is: how can I match opening and closing HTML tags and their
> > content when spread across lines in a string?

> > TIA

> > John O'Connell



Fri, 20 Jun 2003 04:21:52 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Regular Expression Question

2. Regular Expression question

3. Regular expressions question

4. complex regular expression question

5. Regular Expression question

6. Regular Expression question

7. Regular expression question

8. Regular Expressions Question

9. Regular Expressions question

10. Regular Expressions Question

11. Regular Expression question

12. Regular Expressions question

 

 
Powered by phpBB® Forum Software