PHP regep help pls :)

Everything technical and nerdy stuff here plz !

PHP regep help pls :)

Postby dmmh » 11.08.09

need some help with a regular expression

I need to filter text for something like:
tabel 2.1
So it needs to catch that entire piece of text (actually where the word 'table' starts and ends I guess) AND then I want the number (2.1) stored seperately in a variable so I can access it.

help? :D
the meaning of the word cunt....loool

Image
User avatar
dmmh
Godlike
 
Posts: 1134
Joined: 01.19.09

Re: PHP regep help pls :)

Postby dmmh » 11.08.09

thanks for the help cunts

figured it out :)

Code: Select all
$haystack = 'voor een gebruiksfunctie in tabel 2.5 voorschriften zijn'; //example text
$match = '#b(tabel)(s{1})([0-9.]{1,})#'; //(first match the word 'tabel') (second match a single whitespace character) (third match a word which consists of numbers and dots only) -->matches stored in variables ordered in the sequence they are indexed/ started
$replace = "<a href="#" onClick="javascriptwinBRopen('view/table/?tabel_nr=$3', '', 800, 600, 0, 0, 0, 0)">$1$2$3</a>";
return preg_replace($match, $replace, $haystack);
the meaning of the word cunt....loool

Image
User avatar
dmmh
Godlike
 
Posts: 1134
Joined: 01.19.09

Re: PHP regep help pls :)

Postby wurst » 11.09.09

:)
Image
User avatar
wurst
Godlike
 
Posts: 4648
Joined: 07.15.08
Location: Behind U
-----tdm:  
nick: [dswp]GewitterOma
skill: 1122.83
kills: 25960
deaths: 19847
ratio: 1.30
-----bomb:  
nick: [dswp]GewitterOma
skill: 812.172
kills: 3885
deaths: 3541
ratio: 1.09

Re: PHP regep help pls :)

Postby SvaRoX » 11.09.09

Wow you still found time to get the regex working despite 10 hours spent on the server slicing people ? tdm-player58793 - gg ;)
ut4_he_tennis_v0.1
-------------------------
"We are talking about computers here, compared to those I can read women like a book ;P"
Unclefragger
User avatar
SvaRoX
Leader
 
Posts: 1972
Joined: 11.29.08

Re: PHP regep help pls :)

Postby dmmh » 11.13.09

SvaRoX wrote:Wow you still found time to get the regex working despite 10 hours spent on the server slicing people ? tdm-player58793 - gg ;)


ahah, I was mostly in spectator :D

love coding :D
and frigging love ajax in combination with PHP...powerrrrrrrrrrrrr
the meaning of the word cunt....loool

Image
User avatar
dmmh
Godlike
 
Posts: 1134
Joined: 01.19.09

Re: PHP regep help pls :)

Postby SanHolo » 12.17.09

I know this is an old topic, just stumbled upon it. Your RegEx is a little weird and the "." actually matches anything (not just a literal dot), so I bet that it does not work on the following string:

"this tabel is tabel 3.2"

You can simply use:

Code: Select all
#b(tabel)s+([d.]+)#


:)
There is no god.
User avatar
SanHolo
Godlike
 
Posts: 369
Joined: 07.20.08
Location: Switzerland


Who is online

Users browsing this forum: No registered users and 55 guests

Misc