The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
PHP RegEx
Discuss PHP RegEx in the Regex Programming forum on Dev Shed. PHP RegEx Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 29th, 2008, 02:30 AM
|
|
Contributing User
|
|
Join Date: Jan 2008
Posts: 64
Time spent in forums: 8 h 53 m 20 sec
Reputation Power: 6
|
|
|
PHP RegEx
Last edited by ::Quick:: : September 29th, 2008 at 02:32 AM.
|

September 29th, 2008, 10:38 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
You haven't described the problem that well.
Code:
/^(\[[^\]]+\]\s+)?([a-z0-9]{,20})\s+(\d+)%(.*)\s(\d+)/is
[edit] And a more descriptive title would be nice too.
Last edited by requinix : September 29th, 2008 at 10:56 AM.
Reason: that first [...] part is optional
|

September 29th, 2008, 11:10 AM
|
|
Contributing User
|
|
Join Date: Jan 2008
Posts: 64
Time spent in forums: 8 h 53 m 20 sec
Reputation Power: 6
|
|
|
Sorry, I had to go somewhere so I was quickly writing it up.
Basically I need to extract each item in the string into an array:
Also the Regular Expression but be versatile so that it can correctly process any of the strings included in the Pastebin.
Last edited by ::Quick:: : September 29th, 2008 at 11:41 PM.
|

September 29th, 2008, 01:34 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Apparently it didn't like the {,20} syntax.
Code:
/^(\[[^\]]+\]\s+)?([a-z0-9]{0,20})\s+((\d+)\s+)?(\d+)%\s+(\S+)\s*(.*)\s(\d+)/is
[2] = name, [4] = number, [5] = percentage (without the %), [6] = second name, [7] = extra stuff, [8] = second number.
Beware character encoding problems.
|

September 29th, 2008, 09:09 PM
|
|
Contributing User
|
|
Join Date: Jan 2008
Posts: 64
Time spent in forums: 8 h 53 m 20 sec
Reputation Power: 6
|
|
|
Sorry, I still can't get it to work in the RegEx tester or in PHP.
|

September 29th, 2008, 10:06 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by ::Quick:: Sorry, I still can't get it to work in the RegEx tester or in PHP. |
Works fine for me. One, two, and three.
If your PHP isn't working then it's your PHP that's not working.
|

September 29th, 2008, 11:39 PM
|
|
Contributing User
|
|
Join Date: Jan 2008
Posts: 64
Time spent in forums: 8 h 53 m 20 sec
Reputation Power: 6
|
|
Ah, never mind. Fixed it.
php.ini problem.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|