Re: Regular Expression error by Walter
Walter
Mon Jul 17 11:56:44 CDT 2006
<royend@gmail.com> wrote in message
news:1153151109.002182.109800@75g2000cwc.googlegroups.com...
: You are correct in many of your assumptions. I have learned even more
: now, and have come to the same conclusion as you.
:
: Still I have some problems with newlines. It seems my regular
: expression only searches one line at the time... Is there any way to
: make it include several paragraphs of code/text?
:
: In my example the contents between <main> and </main> consist of
: several lines of HTML-code, but my result only gets the first line
: after <main>.
:
: ...
: royend
:
That's happening because the . special character represents any character
except the line-feed character. To capture all the data on multiple lines,
you'll have to use the patttern below.
re.Pattern = "<main>([\s\S]+?)</main>"
: Walter Zackery skrev:
: > See inline comments.
: >
: > <royend@gmail.com> wrote in message
: > news:1153003720.106945.75750@m79g2000cwm.googlegroups.com...
: > :I have been reading some more, and learned something that is supposed
: > : to work for special characters like the "<". In order to search for a
: > : special character it must be "escaped". - for example, to look for
"<",
: > : you have to make your text pattern "\<".
: > :
: >
: > It's true that special characters have to be escaped, but < and > are
not
: > special characters in regular expressions.
: >
: > : Therefore my new RegExp will be like this:
: > : re.Pattern = "/<main/>.*(?/<//main/>)"
: > :
: > : It still produces the same error though....
: > :
: >
: > The error is being thrown because ? is a special character that has to
be
: > escaped, but you didn't escape it. I think that you meant to use it as a
: > special character, but you used it the wrong way. It's not needed here
: > anyway. This is probably the expression you're looking for if you
attempting
: > to capture the contents of the main element.
: >
: > re.Pattern = "<main>(.*)</main>"
: >
: > : Back to the drawing board....anybody with some advice?
: > : royend
: > :
: > : royend@gmail.com skrev:
: > : > Hi.
: > : > I have one script of Regular Expression on two ASP-pages, but it
only
: > : > works on one of them. The code is exactly the same (copy/paste) on
both
: > : > pages still this error occurs on one page:
: > : >
: > : > Microsoft VBScript runtime error '800a1399'
: > : > Syntax error in regular expression
: > : > /admin.asp, line 7
: > : >
: > : > The code:
: > : > Dim re
: > : > Set re = new RegExp
: > : >
: > : > re.Pattern = "<main>/.*(?</main>)"
: > : > re.Global = true
: > : >
: > : > set Matches = re.Execute(text) <-- this is where the error
occurs...
: > : > newTex = Matches.Item(0).Value
: > : >
: > : > The text is a normal HTML page, where I want to find the contents
: > : > between the main-tag.
: > : > Is there anybody who may explain this? Is there really a syntax
error
: > : > in my code?
: > : >
: > : > Looking forward to your answers!
: > : > royend
: > :
: