webdevRefinery Forum: Why doesn't this regex work? - webdevRefinery Forum

Jump to content

Think a topic deserves its own subforum?

Any topic that gets popular here will have a subforum made for it, as long as there are folks around who can answer questions! So if you think wdR is missing something, just talk about it here :)
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rate Topic: -----

User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 06 February 2012 - 05:27 PM (#1)

Why doesn't this regex work?


lil' finger exercise for y'all?
I'm absolutely amazed by my vserver and the first thing I wanted to do with it is install openphoto (because it rocks and I dislike flickr+picasa more and more).

The rewrite rule for openphoto to have nice urls seems to be pretty easy (as shown in the installation guide):

^/(.*)\?*$
=>
index.php?__route__=/$1


the idea is that if I have the url myphotosite.tld/foo/bar?wut=1 it should internally redirect to index.php?__route__=/foo/bar (and NOT __route__=/foo/bar?wut=1).

The problem is: The above regex gives me the latter (i.e. WITH the part after the question mark). I tried to tweak the regex to the following expression:
^/([^?]*)\?*$
to make sure the search pattern would NOT include the ?. This, however, results in a 500 error if there IS a question mark (and normal behavior when there is none, but then the other pattern obviously also works...)

Any ideas what I'm doing wrong?
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
0


User is offline ThatRailsGuy 

  • José the Jalapeño ... on a Stick
  • Group: Members
  • Posts: 4387
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Ruby on Rails,SQL

Posted 06 February 2012 - 05:29 PM (#2)

I don't understand your question, perhaps if you have me an input and an output. I use http://rubular.com/ to play around with expressions, it's ran in Ruby, but works fine with my Java code as well, never tried PHP regex in it.
Posted Image Reliable Rabbit
Reliable Rabbit, my "company."
1


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 06 February 2012 - 05:48 PM (#3)

View Postgibbonweb, on 06 February 2012 - 05:27 PM, said:


^/(.*)\?*$
=>
index.php?__route__=/$1


the idea is that if I have the url myphotosite.tld/foo/bar?wut=1 it should internally redirect to index.php?__route__=/foo/bar (and NOT __route__=/foo/bar?wut=1).

green = input
blue = desired output
red = undesired (but actually obtained by this pattern) output

the regex has nothing to do with PHP, it's run by Cherokee (so C, or whatever)

so in other words I want a patter which matches the bold part of the following:

/foo/bar?wut=1

the greediness of the first group seems to be the problem. Don't know how to get rid of it though?
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
0


User is offline ThatRailsGuy 

  • José the Jalapeño ... on a Stick
  • Group: Members
  • Posts: 4387
  • Joined: 02-October 10
  • Expertise:HTML,CSS,PHP,Java,Javascript,Ruby on Rails,SQL

Posted 06 February 2012 - 05:49 PM (#4)

Quick draft: http://rubular.com/r/lWcL30Iojo
Posted Image Reliable Rabbit
Reliable Rabbit, my "company."
0


User is offline gibbonweb 

  • 兄ヨハネス
  • Group: Members
  • Posts: 1615
  • Joined: 23-June 10
  • LocationMunich(DE)
  • Expertise:HTML,CSS,PHP,Javascript,Python,SQL,Graphics

Posted 06 February 2012 - 05:58 PM (#5)

View PostThatRailsGuy, on 06 February 2012 - 05:49 PM, said:


hm. not bad - I'll have to check if those strings can contain other characters too, but then I'll just add them...

woah, this is even better, based on your draft:
http://rubular.com/r/EutY8Xje4L
(that's the exact thing i need, sorry to throw your first part out - it wasn't wrong, just not what the server config expects ;) )

thanks, awesome!
caution: may contain irony.
NOTE that quality posts can only be guaranteed if a +rep advance payment has been made.
gibbonweb | github | hdr photography

Posted Image
1


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Enter your sign in name and password


Sign in options
  Or sign in with these services