473,472 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

regex failing

I'm runing an xmlHttpRequest to get the site's source code and then
applying the regex

xhr.responseText.split(/<body[^>]*>((?:.|\n)*)<\/body>/i)[1]

Works for google.com. Fails on yahoo.com and imdb.com pages (ex:
http://imdb.com/title/tt0482606/ )

Can someone help me tweak this, or give insight as to why its
failing? I can't spot it
Jun 27 '08 #1
3 1430
noon schreef:
I'm runing an xmlHttpRequest to get the site's source code and then
applying the regex

xhr.responseText.split(/<body[^>]*>((?:.|\n)*)<\/body>/i)[1]

Works for google.com. Fails on yahoo.com and imdb.com pages (ex:
http://imdb.com/title/tt0482606/ )

Can someone help me tweak this, or give insight as to why its
failing? I can't spot it
Maybe...
You didn't mention what it is you WANT your regex to do.
And you didn't say what 'failing' is. An error? An unexpected result?

Regards,
Erwin Moller
Jun 27 '08 #2
That information might help huh. I want it to strip everything
inbetween body tags. The error was that I was either receiving nothing
or receiving the entire html including the head tags etc. I have since
seem to have got it working with this code:

xhr.responseText.split(/<body[^>]*>((.|\n|\r|\u2028|\u2029)*)<\/body>/
gi)[1];

Though improvement suggestions are welcome
Jun 27 '08 #3
noon wrote:
That information might help huh. I want it to strip everything
inbetween body tags. The error was that I was either receiving nothing
or receiving the entire html including the head tags etc. I have since
seem to have got it working with this code:

xhr.responseText.split(/<body[^>]*>((.|\n|\r|\u2028|\u2029)*)<\/body>/
gi)[1];
With

foo<body>...</body>bar

this would give you

...

But you wanted to *strip* everything *in between*, _not_ split.
Though improvement suggestions are welcome
... = xhr.responseText.match(/<body(|\s+[^>]*)>((.|\s)*)<\/body>/i)[1];

is largely equivalent to your code in this case and more efficient.
However, IMHO that is still _not_ stripping everything in between but
*matching* everything in between, which is probably what you meant to say.

Note that (X)HTML is a context-sensitive language which cannot be parsed
with one regular expression (defining a regular language) alone. In your
case it should work because a Valid (X)HTML document MUST NOT have more
than one `body' element.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard Latter | last post by:
Hello All, I am a newbie to the Boost library and I have a question about a simple function. All I would like to do is to create a simple function that can test strings using regular...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
6
by: Extremest | last post by:
I have a huge regex setup going on. If I don't do each one by itself instead of all in one it won't work for. Also would like to know if there is a faster way tried to use string.replace with all...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.