473,549 Members | 2,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find strings between {} using regex?

228 New Member
Hey All,

I have a string that contains substrings in following fashion:

abc 1235 {X} sdsdf {Y} ddielf {JP}....

I want to store all those strings between {} so above would return an array/CSV X,Y,JP.
the following finds the very first occurence only. Any idea on how to make it searcj a;;

Expand|Select|Wrap|Line Numbers
  1. $str = 'a {A} 90';
  2.  
  3. $start = '{';
  4. $end = '}';
  5.  
  6. $pattern = sprintf(
  7.     '/@\[(\d+):\d+:([^\]]+)\]/',
  8.     preg_quote($start, '/'), preg_quote($end, '/')
  9. );
  10.  
  11. if (preg_match($pattern, $str, $matches)) {
  12.     list(, $match) = $matches;
  13.     echo $match;
  14.     }
Jan 28 '16 #1
1 1491
Dormilich
8,658 Recognized Expert Moderator Expert
the main problem is that $pattern lacks your delimiters, simply because sprintf() has nothing to replace.
Jan 29 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4675
by: CV | last post by:
How can I match 'n' number of neighbouring words of a pattern using regular expressions? For example, suppose I am looking for the pattern "length xyz cm" in some text. where xyz is a number - integer or fraction or decimal point. How can I also grab about 3-5 words on either side of the pattern "length xyz cm"? The surrounding words are...
16
9048
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: Regex.Replace(input,":-)","img",RegexOptions.Compiled |
4
3065
by: Ya Ya | last post by:
Hi, I have a string with some fixed text and variable text. For example: "this is a fixed text THE NEEDED INFO more more fixed text". How do I get the the variable text (THE NEEDED INFO) from this string ? A simple example will help. Thanks. ra294@hotmail.com
2
1714
by: shilpi.rustagi | last post by:
hi all.. I have to extract the even and odd number of /(backslash) from a string using regex in C++
4
1805
by: Joe | last post by:
I need to do a find/replace on a column name in DataColumn.Expression. Is there a way to do the following using RegEx? MyColumn 10 and Desc = "This is MyColumn desc" I need to replace the MyColumn which is not in a quoted string. Thanks, Joe
6
4126
by: Nightcrawler | last post by:
Hi all. I have a html table with multiple rows (one row example below). I would like to extract everything within the <tdtags into groups on a row by row basis. The process would be: find the first row, then extract the column data, store data in a textfile, find the next row, extract the column data, store data in a textfile.... and so on...
2
5912
by: KK | last post by:
Dear All I have a string like this: myOutput = myObject.MyMethod(myInput1,myInput2) I would like to parse this string and separate it into 4 groups. group1 contains left of '='. group2 contains right of '=' and left of '.' group3 contains right of '.' and left of '('...and so on. I'm not expert in using Regular expressions. Can some...
0
952
by: rmeshksar | last post by:
Hi, I would like to do text replacement using RegEx and use the following statement: Regex.Replace(input, pattern, replacement, RegexOptions.IgnoreCase) It works fine in all cases except in the following scenario. Replacement of a text with a curreny value: Example: decimal total = 100; string sTotal =...
4
2663
by: CJ | last post by:
Is this the format to parse a string and return the value between the item? Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>"); I am trying to parse this string. <File_Name>Services</File_Name> Thanks
2
3744
by: daveftl | last post by:
Hello, i've tried to extract certain data using Regex in a File. but it seems not working.No errors and warnings have been found. here is my code: Private Sub extractTxt(ByVal inputFile As String) ' this will extract specific text from a ' file using Regular Expressions class in .net Dim DateRegEx As Regex
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.