473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem in multiline regular expression

rizwan6feb
108 100+
Hi everyone! I am having a problem in getting the correct regular expression. I have the following string, and i want to get everything between [htmlcode] and [/htmlcode]

[htmlcode]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
[/htmlcode]


using the following regular expression but this is not working, may be due to multiline issue

$regex="/\[htmlcode\](.+)\[\/htmlcode\]/"
May 21 '08 #1
5 2508
Markus
6,050 Expert 4TB
Hi everyone! I am having a problem in getting the correct regular expression. I have the following string, and i want to get everything between [htmlcode] and [/htmlcode]

[htmlcode]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
[/htmlcode]


using the following regular expression but this is not working, may be due to multiline issue

$regex="/\[htmlcode\](.+)\[\/htmlcode\]/"
i don't know if ' .+ ' is the correct syntax; I normally use ' .* '

Therefore:
[php]
$regex="/\[htmlcode\](.*)\[\/htmlcode\]/"
[/php]
May 21 '08 #2
Atli
5,058 Expert 4TB
Try
Expand|Select|Wrap|Line Numbers
  1. /\[htmlcode\](.|\s)*\[\/htmlcode\]/
  2.  
If memory serves, the . class does not include white-space characters, such as \n and \t, so it would stop at new-lines.
May 21 '08 #3
rizwan6feb
108 100+
Try
Expand|Select|Wrap|Line Numbers
  1. /\[htmlcode\](.|\s)*\[\/htmlcode\]/
  2.  
If memory serves, the . class does not include white-space characters, such as \n and \t, so it would stop at new-lines.
Thanks! It works but also returns the part which contains [htmlcode] i.e returns the pattern as well, the second array contains nothing. I am using preg_match (PHP function). Passing only first 2 parameters.
May 21 '08 #4
Atli
5,058 Expert 4TB
Ahh, the problem is probably that the * is outside the parenthesized subpattern.

Maybe this will work:
Expand|Select|Wrap|Line Numbers
  1. /\[htmlcode\]([\w\W]*)\[\/htmlcode\]/
It basically creates a class with all the alpha-numeric characters... and all the non-alpha-numeric characters.

The entire string should be int the first element of the match array, but the sub-pattern in the second (at index 1).
May 21 '08 #5
rizwan6feb
108 100+
Yes the * was outside parenthesis. This time its working perfectly.
Thank you very much.
May 21 '08 #6

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

Similar topics

2
by: Oriana | last post by:
Hi! I'm trying to 'clean up' this source file using regular expressions in Python. My problem is, that when I try to delete extra lines, my code fails. Here's an example.... /** * *...
1
by: David Elliott | last post by:
I have an expression that works for single line but not multiline. What am I missing? expression = "<div(?<data1>.*?)>(?<data2>.*?)</div>"; MatchCollection mc = Regex.Matches(data, expression,...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
3
by: Gianluca | last post by:
Hi, I'm using regular expressions to extract some information from my vb.net source code files. I have something like this: 1: '<class name="xyz" description="xxxxxx"/> 2: Class xyz ......
3
by: Mark | last post by:
To validate the length of a multiline textbox, I'm told that I have to use a regular expression validator. The regular expression below limits it to 25 characters in length, but if the user enters...
0
by: norton | last post by:
Hi All, I am learning Regular Expression and currently i am trying to capture information from web page. I wrote the following code to capture the ID as well as the Title Dim regex = New...
5
by: Grzegorz Danowski | last post by:
Hi, I'd like to read all lines of caption text from a string: .... Name ="Paragraph" Caption ="The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. " "The...
6
by: Zdenek Maxa | last post by:
Hi all, I would like to perform regular expression replace (e.g. removing everything from within tags in a XML file) with multiple-line pattern. How can I do this? where =...
7
by: wagswvu | last post by:
I have created a regular expression to validate dates in MM/DD/YYYY, MM/YYYY, and YYYY. "((0|1)((0||3))?)?(19|20)\d\d" . How can I make this expression work with a multi-line textbox, so that a user...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.