Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Location
    Tacoma, WA
    Posts
    199
    Rep Power
    0

    Problem with expression


    I need to find:

    "{SomeString ...anything goes here... }"

    Where the streing starts out with "{SomeString" and ends with "}", but can have anything in between.

    I would be using preg_replace...

    I'm not getting anywhere.
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,759
    Rep Power
    9397
    Anything... except a } of course. Remember that.

    { and } are special characters: escape them with a backslash. Use [] for a set, then negate it, and include whatever character you don't want. A * means "any number of" - use that on the character set.

    Comments on this post

    • prometheuzz disagrees : What's it called again? ... Right, thumbing it down. '{' and '}' are not meta characters.
  4. #3
  5. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by requinix
    ...

    { and } are special characters...
    ... in some cases.
    See: http://www.regular-expressions.info/...s.html#special

    Comments on this post

    • requinix disagrees : it's called "dumbing it down"
  6. #4
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Location
    Tacoma, WA
    Posts
    199
    Rep Power
    0
    How about this:
    Code:
    $pattern = '/\{SomeString\s*[0-9a-fA-F\s]\}/';
    to match "Opening Curly Brace + SomeString + Space Char + Any Number of Letters and Numbers and Space Chars + Closing Curly Brace"
  8. #5
  9. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by Weekend Coder
    How about this:
    Code:
    $pattern = '/\{SomeString\s*[0-9a-fA-F\s]\}/';
    to match "Opening Curly Brace + SomeString + Space Char + Any Number of Letters and Numbers and Space Chars + Closing Curly Brace"
    Try it!
  10. #6
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Location
    Tacoma, WA
    Posts
    199
    Rep Power
    0
    Originally Posted by prometheuzz
    Try it!
    I'm not sitting at a machine that has development software installed. Any friendly knowledgeable folks?

    Comments on this post

    • Skipt agrees
  12. #7
  13. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by Weekend Coder
    I'm not sitting at a machine that has development software installed. Any friendly knowledgeable folks?
    What good would it do you if someone here would say "yes that is correct". You will still need to wait when you you get to a system that has the right software to test it yourself. Right?
    Also, when performing an extensive test yourself, you might run into a corner case that you didn't mention here. What if someone here says: "yes, that is the correct regex" and you don't test it properly and therefore don't run into this corner case?

    But yeah, what you said in your post, is more or less correct. I said "more or less" because \s matches not only single white spaces, but also new lines, tabs, etc. But again: test it yourself!

    Note that you can also test your regex-es online. Just Google for "on line regex tester". This one is nice:
    http://regex.larsolavtorvik.com/

    Good luck!

    Comments on this post

    • Weekend Coder disagrees : Nice guy!
  14. #8
  15. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by Weekend Coder
    I'm not sitting at a machine that has development software installed. Any friendly knowledgeable folks?
    B.t.w, are you insinuating something with the cursive word "friendly"?

    Comments on this post

    • Skipt agrees
  16. #9
  17. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Location
    Tacoma, WA
    Posts
    199
    Rep Power
    0
    Originally Posted by prometheuzz
    B.t.w, are you insinuating something with the cursive word "friendly"?
    Yes I am.

    If you're unwilling to be helpful, why waste your time? Your attitude is very unfriendly.

    I made an effort to work it out and asked if it looked good. If you didn't care to waste your time, you should have skipped commenting at all.

    This is *NOT* some IRC channel.

    And, EVEN if it does work, maybe there is a BETTER way to do what I want?

    But clearly you are NOT a helpful person.

    Comments on this post

    • Arty Ziff disagrees : Cool your jets.
    • prometheuzz disagrees : Just returning the favour
    • Skipt agrees : balance
    Last edited by Weekend Coder; February 4th, 2009 at 11:03 AM.
  18. #10
  19. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by Weekend Coder
    Yes I am.

    If you're unwilling to be helpful, why waste your time? Your attitude is very unfriendly.

    I made an effort to work it out and asked if it looked good. If you didn't care to waste your time, you should have skipped commenting at all.

    This is *NOT* some IRC channel.

    And, EVEN if it does work, maybe there is a BETTER way to do what I want?

    But clearly you are NOT a helpful person.
    So by telling you to try something, I am unfriendly? What an ungrateful piece of work you are!
    I wasn't unfriendly to you. I didn't know you had no machine at hand where you could test it. And after you explained why you couldn't test it, didn't I gave you a proper explanation and didn't I explain why I suggested you to test it yourself?

    I won't waste my time on you anymore!
    Last edited by prometheuzz; February 4th, 2009 at 01:34 PM.
  20. #11
  21. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,759
    Rep Power
    9397
    Guys, knock it off. You've both insulted each other thoroughly so call it even.

    Comments on this post

    • Skipt agrees
  22. #12
  23. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by requinix
    Guys, knock it off. You've both insulted each other thoroughly so call it even.
    Ah, I see, to make a point, you have to increase the size of your font. Good to know.

    Granted, my last remark was not necessary (I removed it), but I still find the OP and ungrateful piece of work for calling me unhelpful

    Comments on this post

    • Arty Ziff disagrees : Bahhh. Your both out of line. Thus, I derep you both. Enjoy.
  24. #13
  25. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    I also find it disappointing that people don't seek the discussion but rather "vote" me down using this forum's voting system. The easy way out, if you ask me.
    A shame.
  26. #14
  27. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by requinix
    Anything... except a } of course. Remember that.

    { and } are special characters: ...
    I was mild earlier. The above statement is false: '{' and '}' are not special characters. In some cases '{' is a special character but '}' is never one.
  28. #15
  29. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Location
    Tacoma, WA
    Posts
    199
    Rep Power
    0
    Originally Posted by prometheuzz
    I was mild earlier. The above statement is false: '{' and '}' are not special characters. In some cases '{' is a special character but '}' is never one.
    Well, I've played with it a bit and think I was on the wrong track. From what I can tell...

    What I had was not 'any number of letters and numbers': it only hexadecimal digits (0-F). \s doesn't just match spaces: it matches any whitespace character, including tabs, vtabs, &c., and I think you've applied the * wrongly: modifiers go after the terms they modify.

    So I'm going to try this one:
    Code:
    '/\{SomeString [0-9a-zA-Z ]*\}/'
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo