Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 12th, 2006, 3:50 AM   #1
ktsirig
Programmer
 
Join Date: Oct 2005
Posts: 54
Rep Power: 3 ktsirig is on a distinguished road
PHP & newlines Regular expressions

Hi all!
I have a preformatted text where I want to run a regular expression. The text is something like :
[PHP]
codeA
*->refbrjkgbrkjgbrjukbgreukgbrukgbegurebgrek

klgfhnrjkgnrjgbrejkgbrjkbegjkrbbrkegbrejb

reopjgporejytopjrotjrphjpojprhjtporhtjrph

codeB
*->4p3tuop43tu4optj4rofdgfnreklfnrklefnrkenr

ropeturojgorejgeolgjrelgjrlgrhelkghelghlg

regjrejgoejeojigjreilgjelgjrilgjlerjgelrj
[/PHP]

From each 'paragraph', I want to match the part under codeA and codeB
The problem I have is with matching the newline characters. I write :
preg_match('/code.{1}\n\*->(.*)\ncode./')
but it doesn't match... I think the problem is the newlines
ktsirig is offline   Reply With Quote
Old Feb 12th, 2006, 8:13 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
What I'm going to say may be wrong. I can't lay my hands immediately on the reference I have in mind. The newline may not be interpreted as such inside single quotes.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 12th, 2006, 8:20 AM   #3
ktsirig
Programmer
 
Join Date: Oct 2005
Posts: 54
Rep Power: 3 ktsirig is on a distinguished road
DaWei, thanx for the post...
I tried using double quotes, but doesn't do anything... and the weird thing is that, for instance, spaces are matced with \s but why newlines don't????
I can't figure it out.....
ktsirig is offline   Reply With Quote
Old Feb 12th, 2006, 8:38 AM   #4
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Maybe you have to use \r\n, instead of only \n. Absolutely not sure, though.
Polyphemus_ is offline   Reply With Quote
Old Feb 12th, 2006, 8:53 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Your particular text, as represented in the post box, does indeed contain both a return and a newline:
Hex/Ascii
20 63 6f 64 65 41 0d 0a 2a 2d 3e 72.... (20 is a space)
    c  o  d  e  A \r \n  *  -  >  r ....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 12th, 2006, 10:16 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I don't know how you are producing your string, as shown in the code box of your post. If you produce it with the line breaks as actual codes rather than some unpredictable presentation that varies from display device to display device and system to system, I think you'll find success. In other words,
"codeA\r\n*->refbrjkgbrkjgbrjukbgreukgbrukgbegurebgrek\r\nklgfhnrjkgnrjgbrejkgbrjkbegjkrbbrkegbrejb\r\nreopjgporejytopjrotjrphjpojprhjtporhtjrph"
In the post there are spaces shown (such as after 'nklgfh' and before 'nrjk') that are not present in the actual material.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC