Jump to content

50jkelly

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

50jkelly's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yeah, I've been thinking about this all day and I agree with Crayon Violent. Even if there was an effective way of doing it all in one regex, heaven help anyone who goes back to edit or maintain it, and splitting the functions in php is relatively straightforward...
  2. Hey, I had been thinking about this and I believe this regex is better (it allows any characters in the function body, and should fix your problem with nested brackets). /^\s*function (\w*)\(([\$\w\s\,\-]*)(?=\))\)[\s\r\n]*\{(.*)(?=\}[\s\r\n])/s You're right though, this expression only works on one function at a time, I'll think about this today and see what I can come up with.
  3. Doh! You're right, although you don't need \_ as its covered by \w
  4. Hey hassank1. I had fun with this regex, it's a cool idea! I've come up with a regex that produces the output you want: /^\s*function ([\w\-]*)\((.*)(?=\))\)[\s\r\n]*\{([\w\s\r\n\{\}\$\(\)\=\'\"\!;]*)(?=\}[\s\r\n]*$)/ Using this in PHP: preg_match('/^\s*function ([\w\-]*)\((.*)(?=\))\)[\s\r\n]*\{([\w\s\r\n\{\}\$\(\)\=\'\"\!;]*)(?=\}[\s\r\n]*$)/', $test_string, $matches In this case the $matches array will contain: [0]: The whole function matched, [1]: Function Name, [2]: Parameters, [3]: Function body It's a bit messy and could probably do with some tidying up, but try it and see what you think. If you want it explained just let me know
  5. Hi radi8. The expression you posted worked quite well, the only problem I found was that if the numeric portion of the string was more than 5 characters, a match would still be returned of the first 5 characters. For example, B123456 would return a match for B12345. This is easily solved with a $ at the end of the expression. Here's what I ended up with: /^[a-z]{1,2}[0-9]{1,5}$/i
  6. Hey, the following expression seemed to work for me on that string: /[a-z]+, [a-z]+/i
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.