473,507 Members | 12,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Match Line Breaks using Regular Expression

46 New Member
Hi all,

I wrote the following Javascript function used to execute the Javascript codes from the ajax response which contains both html & javascript.

It works fine, if the javascript codes from the response doesn't have any line break at all.
Expand|Select|Wrap|Line Numbers
  1. function executeJSCodes( html ){        
  2.               var regExp = new RegExp('<script language="javascript">(.*)<\/script>',"gi");
  3.               while( res = regExp.exec(html) ){
  4.         eval(res[1]);
  5.               }        
  6. }
So, please tell me how to match line breaks by using regular expression.

Regards,
Velhari
Jul 1 '08 #1
4 2554
gits
5,390 Recognized Expert Moderator Expert
hi ...

try a replace at first, like this:

Expand|Select|Wrap|Line Numbers
  1. html = html.replace(/(\n\r)+/, '');
just add this to your function as the first step.

kind regards
Jul 1 '08 #2
Velhari
46 New Member
hi ...

try a replace at first, like this:

Expand|Select|Wrap|Line Numbers
  1. html = html.replace(/(\n\r)+/, '');
just add this to your function as the first step.

kind regards
hi,

Thanks for Reply.

I tried your code, it doen't work.

From your regular expression instead of nullifying the line breaks, include this condition in my regular expression for matching line breaks, tab character, space at the beginning and end of string. It works fine now.

Thanks for your valuable suggesstion

For your info, modified code is below;

Expand|Select|Wrap|Line Numbers
  1. function executeJSCodes( html ){        
  2.              var regExp = new RegExp('<script language="javascript">([\r\n\b\s\t]*.*[\r\n\b\s]*)<\/script>',"mgi");        
  3.              while( res = regExp.exec(html) ){            
  4.     eval(res[1]);
  5.              }        
  6. }
Regards,
Velhari
Jul 1 '08 #3
hsriat
1,654 Recognized Expert Top Contributor
I could not understand the purpose of what you are trying to do, though I am able to guess that you are trying to locate the JavaScript inside the html and then execute it.

This doesn't seem a right procedure to me. Please explain the whole thing so that we could think of an alternate solution, if you are willing to go for that.


Regards
Jul 1 '08 #4
rnd me
427 Recognized Expert Contributor
gits was close:

try:
Expand|Select|Wrap|Line Numbers
  1.  html = html.replace(/\r?\n/g, "")
Jul 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1925
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
1
3962
by: Venkat | last post by:
Hi, I am using match function of string to find if a character is there in a string. The function Match is working fine with all the other characters except when the searching character is "+"....
3
18738
by: Derek Stone | last post by:
In my continuing inability to completely understand regular expressions I have a new one for you. I'd like to capture a string "A" unless it is anywhere in between string "B" and string "C". ...
19
2131
by: Tom Deco | last post by:
Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. ...
2
7900
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I mean that the input string could not yet be...
1
7393
by: Laser Lu | last post by:
Hi, all, I'm now writing a program to compress JavaScript code. One puzzle is how to write a regular expression to find out and remove all the redundent blank spaces. However, those blank spaces...
38
15912
by: Steve Kirsch | last post by:
I need a simple function that can match the number of beginning and ending parenthesis in an expression. Here's a sample expression: ( ( "john" ) and ( "jane" ) and ( "joe" ) ) Does .NET have...
1
1505
by: sreemathy2000 | last post by:
My requirement is to read/write a javascript file in a windows applications. this javascript file is used by my website.. function test { var a; //start dim obj ={'abc','bcd','cde','def'};...
14
4959
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
0
7221
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
7313
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
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5619
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,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
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 ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.