Extract balanced parantheses from String
Hi community,
I am getting back to work on LabVIEW after long.
Currently implementing an algorithm and I need to work with tree like structures presented in the form of strings with parantheses.
So, for example, a string such as A(B(c,d),P(q,r),U(V(w),X(y,z,o))) has a tree with root node A, and there are three children of A, namely B, P, U, and all of them also represent a tree (sub-tree of the original tree A). So that, B is the root of the sub-tree where c and d are the two nodes. U also has two children that represent individual sub-trees, namely V (with one child) and X (with three children).
Although, there is one detail, which may actually help the process a bit. The trees are simplified, so that all the nodes that represent some tree (or sub-tree) are just called S.
To extract all these trees, I am going to check one element at a time and then build the sub-trees one by one.
Just thought to ask here if someone has a better idea (or if some function from OpenG may help here if someone has done something similar). Always ready to learn!
Thanks ahead!
Vaibhav
Ok, I just finished the function to validate the input string, extract all the valid sub-trees and list them.
The VI and the required Sub-VI are in the attachment.
This is just to show what output do I need. Any suggestions to improvements are most welcome.
And if someone finds this solution as useful, I would appreciate acknowledgement of that too (Kudos ).
But my main objective is to know how this could be done in a smarter way.
Try to play with the function with different valid and invalid tree automata strings. Be careful with the root symbol.
In the above post I used "S" as the root symbol, and in the VI, I am using "X" by default. So just change either of them.
Try for example,
X(a,b) - valid - 1 tree
X(X(a,b)) - valid - 2 sub-trees
X((a,b)) - invalid
X(a,b)) - invalid
X(X(a,b) - invalid
X(X(a), X(X(b)),X(c,X(d )) ) - valid (it will remove the unnecessary spaces that the user might add mistakenly) - 6 sub-trees.
Could I get these results through regular expressions?
Remark: I didn't put small checks like if the user gives a multi-char string as the Root symbol or things like that, just to implement quickly. I assume the user will not make deliberate mistakes like this.
In the front panel of the main VI (Validate and Extract Sub-trees.VI), you may ignore the array A2, as it was mainly for my debugging purposes. The array A2 is filled while the program runs, and you may see my logic in those cells. But ignore otherwise.
Cheers!
[Edited 03/24/2014: Attachment with private information removed at poster's request]
Vaibhav
Similar Messages
-
Extract 2 characters from string
Hello,
Can anyone help to create a formula to extract 2 characters from the left of "pp" in a field using CR XI?
Field = {MainEstimateDetails.JobDescription} (string)
Sample string details:
"Annual Report 96pp & Cover 12345" - want to be able to show only 96 (from 96pp)
"CTP A4 4pp" - want to be able to show only 4 (from 4pp)
The string length is variable and the "pp" will be in different places each time.
It is probably very simple, but I cannot get itHi,
You can use the InStr function for this. InStr returns the position of the string your are looking for.
NumberVar myPosition;
If InStr ({MainEstimateDetails.JobDescription}, "pp") > 0 Then
myPosition := InStr ({MainEstimateDetails.JobDescription}, "pp")
Else myPosition := 0;
If myPosition <> 0 Then
{MainEstimateDetails.JobDescription} [(myPosition - 2) To (myPosition - 1)]
Else "";
This is a bit longer than I would normally do it but... I use Instr to check if the field has "pp" in it. If it does it will return the character position in the field and I pass that to my variable myPosition.
If myPosition has a value then it parses out the two characters before "pp".
Good luck,
Brian -
How to extract the Datetime from string?
Hello FOlks,
I have the sample data whichi is a string and it contains DateTime part inside it. I worked through half way but am not sure how to get the other part.
The sample data is
Note Added by AARON HILTON at 05/26/2010 14:53 MONEY NOTE ENTERED
Note Added by DEBBIE BILL at 11/16/2009 23:12 MONEY ENTERED
I tried using
substr(d.assignee_note, INSTR(d.assignee_note,'at')+2,length(d.assignee_note)) but it did not have the desired results.
How to just extract the datetime part i.e. 11/16/2009 23:12If your sample data is representative for all the data, you could also try a regular expression:
SQL> -- generating sample data, pretending it's stored in a column called str in a table called t:
SQL> with t as (
2 select 'Note Added by AARON HILTON at 05/26/2010 14:53 MONEY NOTE ENTERED' str from dual union
3 select 'Note Added by DEBBIE BILL at 11/16/2009 23:12 MONEY ENTERED' from dual
4 )
5 --
6 -- actual query:
7 --
8 select trim(regexp_replace(str, '[[:alpha:]]')) str
9 , to_date(trim(regexp_replace(str, '[[:alpha:]]')), 'mm-dd-yyyy hh24:mi') dt
10 , to_timestamp(trim(regexp_replace(str, '[[:alpha:]]')), 'mm-dd-yyyy hh24:mi') ts
11 from t;
STR DT TS
05/26/2010 14:53 26-05-2010 14:53:00 26-05-10 14:53:00.000000000
11/16/2009 23:12 16-11-2009 23:12:00 16-11-09 23:12:00.000000000
2 rows selected.where column STR is, well, a string, DT will turn your string into date datatype and TS will turn it into a timestamp.
It isn't clear how you want to extract the datetime part, but it really matters... -
Extracting numeric data from string
Dear all,
how can i extract a numeric part of a Varchar2 column..
the data is
transaction 111.98 sucess
gsdhgadg 52365.878 hdfjhfd
ttqweqwg3321.7676jdshfjhsf
from all the above strings i want to extract 111.98 ,52365.878 ,3321.7676
how can i do it in teh most efficient way.. is theer any analytical function inplace for doing this?
please help..edogt wrote:
hi,
this is my solution:
declare
anumber varchar2(100) ;
text varchar2(100) := 'transaction. 111.98 sucess' ;
begin
anumber := regexp_substr(text,'[[:digit:]]+(\.[[:digit:]]+)*');
dbms_output.put_line(anumber);
end ;Which doesn't work if you test it against the OP's latest requirement...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'transaction 111.98 sucess' as txt from dual
2 union select 'gsdhgadg 52365.878 hdfjhfd' from dual
3 union select 'ttqweqwg3321.7676jdshfjhsf' from dual
4 union select 'IT2 Power Resis;UPI 2.4900;QTY10' from dual)
5 -- end of test data
6 select txt, regexp_substr(txt, '[0-9]+\.[0-9]+') as num
7 , regexp_substr(txt,'[[:digit:]]+(\.[[:digit:]]+)*') as num2
8* from t
SQL> /
TXT NUM NUM2
IT2 Power Resis;UPI 2.4900;QTY10 2.4900 2
gsdhgadg 52365.878 hdfjhfd 52365.878 52365.878
transaction 111.98 sucess 111.98 111.98
ttqweqwg3321.7676jdshfjhsf 3321.7676 3321.7676
SQL>P.S. you should wrap your code with {noformat}{noformat} tags so that it's displayed properly. ;) -
Extract min timestamp from string
Hello all,
I am trying to query the minimum datetime from a column that is stored as nvarchar(max). There a a few tricky things with this query (at least for me)
- There is more than just the date being stored within each record.
-The position of the datetime is relative- although it does always appear in the format '**(DD-MM-YY at HH:MM PM'
-There are multiple datetimes stored in each record-so not only do I need to locate and capture where there is a datetime, I need to find the minimum datetime within the record
- I can't just change the format that the data is stored in- there is over a decade of information that is stored this way.
Please Help
The column is called 'hdresp'
Here is sample data:
**(03-Apr-14 at 09:44 AM email sent) -- Billy Bob: Upgrade ordered. **(02-Apr-14 at 04:16 PM email sent) -- Sammy Richards: I can give you another cable to if you think that will help but it just might be time for an upgrade. If
you want to go that route I have to ask that you submit another request for New Hardware. **(02-Apr-14 at 03:17 PM email sent) -- Paul Smith: Michael Stop by my desk when you have a second.
-What i would like to end up with is a query that identifies '02-Apr-14 at 3:17 PM' as the minimum time and converts it to 'YYYY-MM-DD HH:MM:SS' -for example '2014-04-02 15:17:00'
Thanks!Thank you everyone for your help!
I ended up using this to extract and convert the minimum time from a string:
SELECT CONVERT(datetime, REPLACE(LEFT(RIGHT(hdresp, PATINDEX('%(**%', REVERSE(hdresp)) - 1), 21), 'at ', ''))
from tblhdmain
where hdindex = 211458
Which gave me the result:
2014-04-02 15:17:00.000 -
Extraction of Numbers from string in oracle
Dear All,
I have a AplhaNumeric field in my source table which holds the string with numbers and caharcters .i need to extract only numbers and to load into the target table which of number type.
can any one suggest me about how to do this?
regards
kumarHi ,
I have a table called smitems with column smitmqtyremarks which holds alpha numeric characters .nearly 180 records exists in this table.
i need extract numbers for this field and load into my target tables.
here i am giving sample rows for this field :
smitmqtyremarks
13 قطعة
4 لحاف
31 قطعة
120 قطعة
57 قطعة
110 قطعة
127قطعة
169 قطعة
12 مفرش
10 مفارش
110 قطعة
170 قطعة
20 خرطوشة
28 قطعة
60قطعة
70 قطعة
80 لعبة
70 قطعة
20 قطعة
60 قطعة
50 قطعة
10 رولات
4 رولات
35 دسته
50دستة
7 رول
3 اثواب قماش
خمسة خرطوشة سجائر
50 جاكت حريمى ورجالى
10 رول اقمشة 4 دسته
420 جوارب اطفال
60 خرطوشة سجائر
12 رول
15 خرطوشة
110 علبة
45 قطعة
40 قطعة
44 قطعة
22 قطعة
3 خرطوشة
468 قطعة
38 قطعة
80 رول قماش
2 رول
6 رول اقمشة
13 رول اجنبى الصنع
100 دسته صينى الصنع
18 رولات ملابس
10دسته
90قطعة
33 قطعة
39 قطعة
42 قطعة
300 ايشارب
500 قطعة
19000 ك 0ج
607 قطعة
24 قطعة
45 قطعة
40 اروسه
5 رول اقمشة اجنبية الصنع
75 قطعة
5 قطعة
4 رول
26 قطعة
50قطعة
105 قطعة
650 جرام
65 قطعة
50 خرطوشة
4 خرطوشة
80 قطعة
100 بنطلون
500 قطعة
40 قطعة
42قطعة
1 خرطوشة
14 قطعة
80 قطعة
7 خرطوشة سجائر
230 لمبة
50 قطعة
50قطعة تليفون
14 كرتونة
4 كرتونة احذية
17 كرتونة خزف
22 لحاف
16كرتونة ادوات صحية
8كرتونة
28 كرتونة
2كرتونة
15كرتونة
115 قطعة
6448
1937قطعة
1937 قطعة
2628كجم
6.980طن
9 كرتونة
18 شفاط
صواميل حديد
3كرتونة +20 قطعة
39.480طن ق.غ سيارات
25كرتونة مصنوعات خزفية
50بنطلون
8 كرتونة كلبسات
20كرتونة اكسسوار حريمى
279كرتونة لحوم
38 اطار كاوتش
10كرتونة
4كرتونة
10كيلو
عدد5 ماكينات
41سيارة
سيارة
90 قطعة ملابس
22250كجم
1793كجم
1371كرتونة زجاج
مستندى
252شاشة
5كرتونة
320قطعة
45خرطوشة
98 قطعة
10لفات
25كجم
320كجم
5كراتين
47طرد
50قطعة
117كجم
1200 قطعة ملابس
5كجم
75جهاز
40قطعة
5كراتين
10كجم
250ق
200ق
200 توب
20لفة
30لفة
2دستة
95قطعة
70قطعة
57523طن طلمبات مياه
43732كجم
755كرتونة
10.645طن
1537طرد
11751كجم
مكبس
77426.80متر
2600قطعة
339طن
15120كجم
مختلفة
267طرد
1200كجم
189عبوة
499كرتونة
10000كجم
960طرد
15.770كجم
111قطعة
174طرد
22000كجم
473000علبة
6720كجم
145خرطوشة
2500طن
3660كجم
27824كجم
8682كجم
14000كجم
6400كجم
133كرتونة
2738كجم
the characters are in arabic here.
hope it clears my issue.
please suggest me the right query for this to get only numbers
thanks
kumar -
Extract number value from string
Hi,
I am getting a string value like bellow.
'2222jhone'
'123344Sam'
'11Tim'
i want to extract only number value.Can anybody help to prepare reg expression.
TahnksYou NEVER want to use REGEXP_REPLACE when looking to query fields with numbers only because you are actually changing the data by removing or replacing with something that was not originally in the dataset. Use REGEXP_LIKE - SEE BELOW.
SELECT <FieldNames>
WHERE REGEXP_LIKE(<FieldName>, '^[[:digit:]]+$')
--This will only return fields that contain NUMBERS ONLY. -
Extracting the xml from string and parse it
Hi all,
I have a webservice, and calling one of the methods, returns xml data but store this data in a string.
For example:
String str = keysstub.getUserLMLArray(UserID,hash, Provider, Filter.ALL,TimeStampString).getXmlResults();returns <id>123456</id><id>123457</id><id>123458</id><id>123459</id><id>123461</id>and stores it in str.
I have to take read this xml from the string and parse it accordingly to retreive the data from it.
Please suggest how i can parse this xml from the string. it will be of great help. Code snippets from anyone would be of great help
Thanks and Regards,
Shikha* Get DOM document from a string containing valid XML.
* @param string String to read XML content from.
* @param varargs Optional arguments: 1: Validating?, 2: NamespaceAware?
* @return DOM document or null if failed.
* @throws Exception if failed.
static public Document toDocument(String string, boolean... varargs) throws Exception {
Document result = null;
if (string != null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
if (varargs != null && varargs.length > 0) {
int count = varargs.length;
if (count > 0) {
factory.setValidating(varargs[0]); //needs error handler
if (count > 1) {
factory.setNamespaceAware(varargs[1]);
DocumentBuilder db = factory.newDocumentBuilder();
result = db.parse(new InputSource(new StringReader(string)));
}//else: input unavailable
return result;
}//toDocument()and don't forget that the string must be valid xml, so in your example the header is missing and the first element must embrace all subsequent elements, e.g.
<?xml version="1.0"?>
<ids>
<id>123456</id><id>123457</id><id>123458</id><id>123459</id><id>123461</id>
</ids> -
Extract first name from string
Post Author: gronkette
CA Forum: General
If I have the followng list:
SCHEELS, Julie
CURTIS, Tobi
JOHNSON, Dawn etc....
How do I extract the First name following the comma? I've been able to extract the Last name several ways.
thanks!Post Author: gronkette
CA Forum: General
When I use the Split function with [2]..... I get the following error:
A subscript must be between 1 and the size of the array...
works great with [1].
-j- -
How to extract specific line from a string
Hi guys.
I?m starting to work with java...
i have the following data inside a string variable:
0 rows inserted.
0 rows updated.
0 rows ignored.
98 rows marked as deleted.
0 rows have no country.
3345 rows have no geo.
0 rows are invalid.
what i want to do i to extract the number of rows marked as delete.
I think that i figured out how to extract the number from this line :"98 rows marked as deleted."
but how do i get to that line?
I hope you can Help me. Thanks.the string is the result from a Function... this function gets the info from a store procedure...
rta = "Results for " + dh.getSource() + " source:\n" +
dh.getInsertedCount() + " rows inserted.\n" +
dh.getUpdatedCount() + " rows updated.\n" +
dh.getIgnoredCount() + " rows ignored.\n" +
dh.getDeletedCount() + " rows marked as deleted.\n" +
dh.getNoCtryCnt() + " rows have no country.\n" +
dh.getNoGeoCnt() + " rows have no geo.\n" +
dh.getInvalidCnt() + " rows are invalid.\n";
i can?t change this function...
so i need to work with the returned value...
i what thinking to use the following method to extract te number...
private int GetNumericValue(string sVal)
int iFirst, iCharVal, iEnd;
int iMult = 1, iRet = 0;
char[] aNumbers = "1234567890".ToCharArray();
iFirst = sVal.IndexOfAny(aNumbers);
iEnd = sVal.LastIndexOfAny(aNumbers);
if (iEnd < 0)
return 0;
string subStr = sVal.Substring(iFirst, iEnd - iFirst + 1);
iEnd = subStr.Length - 1;
while (subStr.Length > 0)
iCharVal = int.Parse(subStr[subStr.Length-1].ToString());
iRet += iMult * iCharVal;
iMult *= 10;
if (iEnd <= 0)
break;
subStr = subStr.Substring(0, subStr.Length - 1);
iEnd = subStr.LastIndexOfAny(aNumbers);
subStr = sVal.Substring(iFirst, iEnd + 1);
return iRet;
but i still need the 4rd line to extract the number -
How to extract substring from string... how to find the index?
suppose i have a string like
"string1 string2 string3 string4 string....stringK...stringN"
i would like to extract the substring from string4 to stringK-1
where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
is there a function to extract the substring from string4 to stringK-1
or is there a function i can use to determine the index of the end of string4 and the start of stringK?
thks!If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
If you wanna get real fancy, use the split method of String. -
Scan from string and extract string between delimiter
Hello,
Basic questions. Is it possible with the scan from string regular expression to extract the string that are within the specified delimiters. Here is an example:
\\Name of folder 1\Name of folder 2\Name of folder 3\File Name
Can the scan from string output the following by specifying the right regular expression:
Name of folder 1
Name of folder 2
Name of folder 3
File Name
I have tried \\\\%s\\%s\\%s\\%s but the %s stops at the first white space.
Thanks,
Michel
Solved!
Go to Solution.RavensFan suggested the appropriate function for your requirement, however you can also use an alternative, which is 'Spreadsheet String To Array'.
I am not allergic to Kudos, in fact I love Kudos.
Make your LabVIEW experience more CONVENIENT. -
Hyperion Brio: Computed Item Extract Number From String
I would like to extract a number from a string in a computer item. For example if I had a string such as "The customer purchased $5.00 of footballs", I would like to remove only the 5.00 from the string. I would have to use the java functions in the results. Any suggestions on how to do this?
you can do this in the Results section with a computed column using the native string functions. to break it down i have split it up a bit.
strval is you string "The customer purchased $5.00 of footballs"
position of $ = 25
Instr ( strval, '$', 1, 1 )
the starting position of the amount would then be 26
Instr ( strval, '$', 1, 1 ) + 1
position of decimal after $ = 26
Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 )
using Substr function you need to pick the string, the start value and the number of characters.
string
= strval
start position
= Instr ( strval, '$', 1, 1 ) + 1
number of characters - location of decimal minus the start position plus 3 to get the cents
= Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 ) + 3
put all together
Substr( strval, Instr ( strval, '$', 1, 1 ) + 1, Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 ) + 3 ) * 1
the multiply by 1 converts the string to number -
I'm trying to search a particular value in a string file. The string contains many parameters followed by their values and units. I want to identify and extract, as a number, the value of a particular parameter. The program will basically ask the user to type in (or select from a list of given) parameters in a dialogue box. Then it should display the value of the parameter.
The string I'm trying to work with, is of the form:-
SensorOneInMM,34585
BatteryVoltageInmV,19761
BattTemp1InC,20
CliffDistanceLeftInMM,60
CliffDistanceRightInMM,60
RightSensor,0
LeftSensor,0
CurrentInmAforMotor, 789
TestingCurrentInmA, 123
Temp1InC,28
Temp2InC,28
BaseCurrentInmA,1342
ChargeInmV,218
CurrentInmA,9999
NotConnected3,0
Now, for example the value I want to read is the one in Blue color. But the expression, "CurrentInmA" appears several times, in the string. How can I identify the value of the parameter in Blue color??
Thanks for helping out an amateur!!!
Cheers.Rajat
I think you want to extract the value from specific string..
you can get number of post releted to your question...few are follow
Post 1
Post2
also see attached vi which specific to your problem..
Attachments:
Extract frm string.png 21 KB -
I want to extract float from string (%f %s) or (%s %f) separated by tab, whitespace etc., Since I am using jdk1.3.1 I can't use regular expression can anybody suggest a simple (one or two or few line code - compact) to get the float in (sign+/-)#.#### format ignoring other characters ?
I tried:
e.g.,
String d="4.000 [tab]4";
source string resulted from "SUBSTRING query of mySQL" can be of :
" -4.543 XYZ ",
" XYZ -4.546 ",
" xx-yy 6.58 3 ",
"6.0 xxx yyy zzz",
the expected results for float from the string should be:
-4.543
-4.546
6.580
6.000
If String containing data separated by comma:
e.g.,
"4.120 1 ,
AAXXFE ,4.206 1 ,
4.000 1,
4.201 1,
4.189 1,
4.204 1,
S DDERSF-RSA"
The result should be: "4.120,4.206,4.000,4.201,4.189,4.204,0.000"
The string is created by:
ResultSet rs1 = stmt.executeQuery(S1);
while (rs1.next()) {
String d = rs1.getString("SUBSTRING(FIELD1,LOCATE(\""+s2[i]+"\",FIELD1)+"+ k_st + ","+ length+")");
System.out.print(d+",");
May be I don't know how to use the following:
float f1 = Float.parseFloat(d);
===
String pattern = "###.###";
//float value = -2100.578f;
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(d);
System.out.println(d+" " + pattern + " " + output);
===Hi
You made the best choice. JRegex is closer to java.util.regex.* and fine works with excellent performance in any JVM version so you can use examples/tutorials from both JRegex and Java.Sun.Com to learn more about regular expression.
About the regular expression in my last post, there are two capturing groups: the first for float numbers in IEEE format specification (also see Java Language Specification) and the second for any sequence of chars, groups using with any amount of blank spaces (spaces, tabs, etc :: see regular expression definition) as delimiter. The anchors "^" and "$" are being used to exactly match pattern in target string and you can relax this constraint as needed.
How to use JRegex? no secrets!
import jregex.*;
// a float number and string with any blank delimiter
String patternString ="^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?)\s+(.*)$";
Pattern pattern = new Pattern(patternString); // different from Sun regex package syntax
// below is identical in both packages
Matcher m = pattern.matcher(anyTargetString);
if (m.matches()) {
Double d = Double.parseDouble( m.group(1) );
String scratch = m.group(2);
// your stuff goes here
..Remember to put JRegex jarfile in classpath!
Regards and Success.
Maybe you are looking for
-
Key Generation, doesnt work
Hi, every body I want to generate new Material Number automatically for new Materials I have done the following steps - I have set Key Mapping to YES in Products main table - In the remote systems I added a new remote system called SAP_ECC - In this
-
How do I share directories between my iMac and Macbook Pro?
Hi there, I have a Macbook Pro (13 inch, Mid 2010, 8Gb RAM and 1Tb SSHD drive) and an iMac (2012 model, 8GB RAM, 1TB hard drive). Both run the most recent version of Yosemite. At the moment I tend to use the iMac as the master computer, its the one I
-
My problem is how to transfer itunes account authorization from my old mac mini to new imac? When I try to synchronized my ipod touch with new imac and transfer all my app is always failed. Do I have to transfer all files from mac mini to imac?
-
SD card reader not working on iMac
The SD card reader slot on my iMac has stopped picking up cards. When I insert a card, it fails to mount. This used to work fine, and still does if a card is inserted while booting up. But after it has been ejected, it will fail to mount again. I've
-
Downloading of apps updates not installing
My daughter's iPod touch 5 is not installing the update to her apps. Not sure what to do. She is upset because one of the apps is instgram