473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Question on PHP regular expressions

In PHP I have many more options for functions that do regular
expression than I did in Perl. My question is what is the best one to
use for doing the following:

Give the following:
{Somestring.somestring.somestring} blah blah {somestring} value here
not used {more.text.here}

I want an array like the following:
[0] =Somestring.somestring.somestring
[1] =somestring
[2] =more.text.here

So basically I just want to capture the contents (alpha-numeric +
periods) inside of curly braces.

Thanks for any help.

Nov 8 '07 #1
2 1424
sberry <se**@buildingonline.comwrites:
In PHP I have many more options for functions that do regular
expression than I did in Perl. My question is what is the best one to
use for doing the following:

Give the following:
{Somestring.somestring.somestring} blah blah {somestring} value here
not used {more.text.here}

I want an array like the following:
[0] =Somestring.somestring.somestring
[1] =somestring
[2] =more.text.here

So basically I just want to capture the contents (alpha-numeric +
periods) inside of curly braces.

Thanks for any help.
This should get you started:

$string = "{Somestring.somestring.somestring} blah blah
{somestring} value here not used {more.text.here}";
$pattern = '/\{.+?\}/';
preg_match_all($pattern, $string, $matches);
print_r($matches);

Hope that helps,
Nov 8 '07 #2
On Nov 8, 11:17 am, Carl <c.gro...@gmail.comwrote:
sberry <s...@buildingonline.comwrites:
In PHP I have many more options for functions that do regular
expression than I did in Perl. My question is what is the best one to
use for doing the following:
Give the following:
{Somestring.somestring.somestring} blah blah {somestring} value here
not used {more.text.here}
I want an array like the following:
[0] =Somestring.somestring.somestring
[1] =somestring
[2] =more.text.here
So basically I just want to capture the contents (alpha-numeric +
periods) inside of curly braces.
Thanks for any help.

This should get you started:

$string = "{Somestring.somestring.somestring} blah blah
{somestring} value here not used {more.text.here}";
$pattern = '/\{.+?\}/';
preg_match_all($pattern, $string, $matches);
print_r($matches);

Hope that helps,
Thanks. That is exactly what I wanted to do. I just added the
PREG_OFFSET_CAPTURE so I could also track the string offsets of the
matches.

Nov 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Dwayne Epps | last post by:
I've created a function that checks form fields that only will have letters. This is the script: <script type="text/javascript" language="javascript"> function validateString(field, msg, min,...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
4
by: OneSolution | last post by:
I am trying to write a regular expression that will match all the exceptions generated in my application log file. I have done it as such: \bjava\.\w+\.\w+Exception: However, there are two...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.