473,787 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regex multiline modifier and windows line endings


In regex, ^ and $ shoudl match start/end of a line when the 'm' /multiline
modifier is set -- however I just spent the better part of the day trying
to figure out why it wasn't working as expected. I used the query
test$
....and the text
test
test
test

Only the last instance of test would match -- that is expected without the
multiline flag. ( http://tinyurl.com/dx86w ) however they should each
match with the multiline flag so long as there's no additional whitespace
after the fact ( http://tinyurl.com/7bap6 ).

Finally, out of ideas, I replaced \r\n with \n on all of my _POST data --
and presto, it worked. So, my question is -- why won't it work on data
with windows line endings? Is there a built in function for changing the
line ending style or something? It seems there should be a more elegant
solution than running a find/replace on all of my user-input just to make
sure the line ending style are liked by PCRE.

Thanks

A.
Jan 31 '06 #1
2 4398
On Tue, 31 Jan 2006 15:41:47 -0500, Allen wrote:

In regex, ^ and $ shoudl match start/end of a line when the 'm' /multiline
modifier is set -- however I just spent the better part of the day trying
to figure out why it wasn't working as expected. I used the query
test$
...and the text
test
test
test

Only the last instance of test would match -- that is expected without the
multiline flag. ( http://tinyurl.com/dx86w ) however they should each
match with the multiline flag so long as there's no additional whitespace
after the fact ( http://tinyurl.com/7bap6 ).

Finally, out of ideas, I replaced \r\n with \n on all of my _POST data --
and presto, it worked. So, my question is -- why won't it work on data
with windows line endings? Is there a built in function for changing the
line ending style or something? It seems there should be a more elegant
solution than running a find/replace on all of my user-input just to make
sure the line ending style are liked by PCRE.

Thanks

A.

Allen, I've never encountered such problem because I normally
clean up all "\r" characters, whenever I encounter them,
but there is a parameter "auto_detect_li ne_endings" in your php.ini
which is normally set to "Off".

--
http://www.mgogala.com

Feb 3 '06 #2
On Fri, 03 Feb 2006 07:40:04 -0500, Mladen Gogala <go****@sbcglob al.net>
wrote:
On Tue, 31 Jan 2006 15:41:47 -0500, Allen wrote:
Allen, I've never encountered such problem because I normally
clean up all "\r" characters, whenever I encounter them,
but there is a parameter "auto_detect_li ne_endings" in your php.ini
which is normally set to "Off".


That'll probably do it. In my code, I never use \r -- the problem was
from user-input, which hadn't occurred to me to manually clean up. Thanks
much.
Feb 6 '06 #3

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

Similar topics

5
2145
by: Ali Eghtebas | last post by:
Hi, I've made this regex to catch the start of a valid multiline comment such as "/*" in e.g. T-SQL code. "(?<=^(?:*'*')*?*)(?<!^(?:*'*')*?--.*)/\*.*?$" With Multiline option on. As we know the T-SQL single line comment starts with a "--" and the string character is a "'". Considering all this, from these lines below the pattern will only catch "/*
2
1876
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to parse the new language, Delphi/Pascal. Source to the highlighter is avail here: http://www.dreamprojections.com/SyntaxHighlighter/Default.aspx ********************************************** COMMENTS
2
1650
by: Mortimer Schnurd | last post by:
Hi All, I am a VB 6 programmer who is now trying to learn C#. In doing so, I am trying to convert some of my VB modules to C#. I routinely user Reg Expressions in VB and am having some trouble trying to use Regex in C#. Basically, I have a fixed format text file which I need to validate prior to using in a program. The validation insures the data format matches what the program is expecting to find in the file. The pattern I am trying to...
6
2529
by: BigAl | last post by:
Perhaps someone here can help me out... RegEx: "^.*\d{5}(-\d{4})?.*$" Intended Purpose: To strip out the City/State/ZipCode line from a signature. Sample Text: Joe Jackson 131 W. 5th Street New York, NY 10023
5
10187
by: JackRazz | last post by:
Anyone know the regular expression to match a blank line where the byte sequence is "0D 0A 0D 0A" ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas? Thanks - JackRazz This is the code fragment I'm trying Dim r As Regex, m As Match, i As Integer
5
5105
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated by a tool. ' Runtime Version: 1.1.4322.2032 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </autogenerated>
4
3135
by: Fuzzyman | last post by:
Hello all, I'm handling some text files where I don't (necessarily) know the encoding beforehand. Because I use regular expressions to parse the text I *must* decode UTF16 encoded text (otherwise the regexes split on byte boundaries). I can recognise UTF8 and BOM and remove (but not necessarily decode). For UTF16 it seems that the Python codec will automatically remove the BOM. Having detected it (to trigger a decode) is it considered
3
2022
by: ommail | last post by:
Hi! I have a simple regural expression: \w+$ and text to match: abc dddd ggg hhh
2
5902
by: felciano | last post by:
Hi -- Is there a standard way to use the csv module to export data that contains multi-line values to Excel? I can get it mostly working, but Excel seems to have difficulty displaying the generated multi-line cells. The following reproduces the problem in python 2.5: import csv
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.