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
|
Problem with expression
Discuss Problem with expression in the Regex Programming forum on Dev Shed. Problem with expression 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:
|
|
|

February 2nd, 2009, 04:40 PM
|
|
Permanently Banned
|
|
Join Date: Sep 2007
Location: Tacoma, WA
|
|
|
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.
|

February 2nd, 2009, 08:59 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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.
|

February 3rd, 2009, 03:42 PM
|
|
|
|

February 4th, 2009, 12:06 AM
|
|
Permanently Banned
|
|
Join Date: Sep 2007
Location: Tacoma, WA
|
|
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"
|

February 4th, 2009, 10:08 AM
|
|
|
Quote: | 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!
|

February 4th, 2009, 10:11 AM
|
|
Permanently Banned
|
|
Join Date: Sep 2007
Location: Tacoma, WA
|
|
Quote: | Originally Posted by prometheuzz Try it! | I'm not sitting at a machine that has development software installed. Any friendly knowledgeable folks?
|

February 4th, 2009, 10:21 AM
|
|
|
Quote: | 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!
|

February 4th, 2009, 10:22 AM
|
|
|
Quote: | 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"?
|

February 4th, 2009, 10:59 AM
|
|
Permanently Banned
|
|
Join Date: Sep 2007
Location: Tacoma, WA
|
|
Quote: | 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.
Last edited by Weekend Coder : February 4th, 2009 at 11:03 AM.
|

February 4th, 2009, 12:31 PM
|
|
|
Quote: | 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.
|

February 4th, 2009, 12:57 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Guys, knock it off. You've both insulted each other thoroughly so call it even.
|

February 4th, 2009, 01:35 PM
|
|
|
Quote: | 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
|

February 4th, 2009, 02:40 PM
|
|
|
|
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.
|

February 4th, 2009, 02:42 PM
|
|
|
Quote: | 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.
|

February 4th, 2009, 03:02 PM
|
|
Permanently Banned
|
|
Join Date: Sep 2007
Location: Tacoma, WA
|
|
Quote: | 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 ]*\}/'
|
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
|
|
|
|
|