Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 9th, 2008, 07:12 PM
mwild8's Avatar
mwild8 mwild8 is offline
Spontaneously Present
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2005
Posts: 1,149 mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 15 h 26 m 2 sec
Reputation Power: 116
Help with lookbehind assertion and fixed width

ok how do i make a variable length lookbehind in php?

php Code:
Original - php Code
  1.  
  2. (?<![\s]*to[\s]*)

http://www.perl.com/doc/manual/html/pod/perlre.html
__________________
I see Cosmos in Pixels.

Integral

Last edited by mwild8 : September 9th, 2008 at 08:09 PM.

Reply With Quote
  #2  
Old September 9th, 2008, 08:23 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,698 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 53 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
[edit] You can't do variable-length negative lookbehinds. At least not in PHP.

Reply With Quote
  #3  
Old September 9th, 2008, 08:25 PM
mwild8's Avatar
mwild8 mwild8 is offline
Spontaneously Present
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2005
Posts: 1,149 mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 15 h 26 m 2 sec
Reputation Power: 116
no that wont work.

you get this

Quote:
[09-Sep-2008 19:35:45] PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 104



in the link i provided

Quote:
(?=pattern)

A zero-width positive lookahead assertion. For example, /\w+(?=\t)/ matches a word followed by a tab, without including the tab in $&.

(?!pattern)

A zero-width negative lookahead assertion. For example /foo(?!bar)/ matches any occurrence of ``foo'' that isn't followed by ``bar''. Note however that lookahead and lookbehind are NOT the same thing. You cannot use this for lookbehind.

If you are looking for a ``bar'' that isn't preceded by a ``foo'', /(?!foo)bar/ will not do what you want. That's because the (?!foo) is just saying that the next thing cannot be ``foo''--and it's not, it's a ``bar'', so ``foobar'' will match. You would have to do something like /(?!foo)...bar/ for that. We say ``like'' because there's the case of your ``bar'' not having three characters before it. You could cover that this way: /(??!foo)...|^.{0,2})bar/. Sometimes it's still easier just to say:

if (/bar/ && $` !~ /foo$/)

For lookbehind see below.

(?<=pattern)

A zero-width positive lookbehind assertion. For example, /(?<=\t)\w+/ matches a word following a tab, without including the tab in $&. Works only for fixed-width lookbehind.

(?<!pattern)

A zero-width negative lookbehind assertion. For example /(?<!bar)foo/ matches any occurrence of ``foo'' that isn't following ``bar''. Works only for fixed-width lookbehind.


i kind of get it, but its still sinking in. looking for a clear answer as to why i cant make it a variable length i.e. your solution

i dont understand
Quote:
cover that this way: /(??!foo)...|^.{0,2})bar/. Sometimes it's still easier just to say:

if (/bar/ && $` !~ /foo$/)

Reply With Quote
  #4  
Old September 9th, 2008, 08:40 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,698 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 53 m
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
My first reply was because I had flipped the ! and > in my head. I saw (?!< (non-capturing, has a <) instead of the (?<! (negative lookbehind) you posted. Thus the edit.

It's just a limitation of the engine, which PHP copied to some extent. There's just no support for that kind of thing.

Reply With Quote
  #5  
Old September 9th, 2008, 08:57 PM
mwild8's Avatar
mwild8 mwild8 is offline
Spontaneously Present
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2005
Posts: 1,149 mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level)mwild8 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 15 h 26 m 2 sec
Reputation Power: 116
yea i understand the logic behind the no support.

basically its fine for a lookahead because it goes until the end. but a lookbehind has the opportunity for an endless recursion loop. meaning i could box it inbetween two "to"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Help with lookbehind assertion and fixed width

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap