infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Read Only Archives
Cloverleaf
Cloverleaf
Searching for a String
Jerry Magrann
I have a document interface sending a multi page report in just one OBX.5. I'm being asked to find a particular string that could be anywhere in the field, never in the same position which I have done using regexp. My problem is I now need to pull the date that is after that expression, so I'm trying wildcards, but can't get it to work. Here is an example: The patient was seen on: 21Sep2014 13:52
I can find the string "The patient was seen on:" but also need the date and time that follows, but since that is always changing, how can I get that part of the string?
Find more posts tagged with
Clovertech
Comments
Jim Kosloskey
Take a look at the string command.
Specifically the string first and string range (if you will be using arguments to your proc then perhaps the string length will be useful as well).
Of course this assumes you want the first occurrence of the text and the date follows that occurrence.
So you know the length of the text you want to search for (let's say 12) - or you get that with the string length.
Now string first will return either the index of the first character of that text in the target string or a -1 if the text is not found.
If the text is found then you adjust the index returned by the length of the text plus any spaces, etc until the date should start - that become the start point for the string range.
The end point will be the start point plus the offset of the length of the date (hopefully the date s always formatted the same).
Then do the string range and you should have thee date (you may need to adjust your offsets one up or down).
That is one way to do this.
Jerry Magrann
I've been trying to use string, but I can't seem to figure it out to pull the 12 characters after finding the expression. Here are my variables:
set seen "The patient was seen on:"
set match [string range $seen end 12]
I find the expression "The patient was seen on:", but the match to get the characters with the date after doesn't pick the characters / date up.
Keith McLeod
Many ways to do this.
Jerry Magrann
Keith - I see what you're trying to do, and I'll admit I don't use regexp that much, so I'm think I'm having trouble with the command - here is more of where I have to look for the string: wpparid0EplainEf1Efs23 The patient was seen on: 21Sep2014 13:52.EparX00\Ewpparid0EplainEf1
How should I set my variable and then output the string?
Keith McLeod
regexp -- {.*The patient was seen on:s+(d{2}[A-Za-z]{3}d{4}s+d{2}:d{2}.*) $obx_5 {} date
I added .* both in the beginning and at the end. The value you are after should still fall into the date variable.
.* means 0 or more characters
Jerry Magrann
OK, I'm almost there, the light bulb in my brain is dim, but at least it's on now. I have finding the string with the regexp, but I'm not able to dump the string into a variable or output the way you did declaring the date - thoughts?
Jerry Magrann
I have my code searching to find the expression as:
if {[regexp {The patient was seen on:s+(d{2}[A-Za-z]{3}d{4}s+d{2}:d{2})} $obx_5] == 1} {
set seen_flag 1
}
This gives me the flag indicator that the expression is there to make other changes such as changing other fields in the message, but I'm not sure how to grab the string of the actual expression with the date.
Jim Kosloskey
string first $seen $sourcedata start
Where $seen is the text you are searching, $sourcedata is the text you want to find $seen and start will become the index of $sourcedata where the first character of $seen was located.
So let's say the first position in the inbound source occurs in the 5th position of the source and the length of $seen is 10 then you need to add 10 to $start to give you the start for string range (you may need to adjust one up or down).
Now $start points to the first character following the end of $seen in $sourcedata. If your date starts right there then $start is correct otherwise you may need to add more to $start.
Now set $done to the sum of $start and 12 (assuming the date is 12 characters).
So the string range would look like this:
string range $sourcedata $start $done
The result of which should be your date.
I have not actually tested any of the above but I think the essentials are correct.
If you still want to investigate using string and are having issues email me and we can do this off line.
Keith McLeod
if {[regexp -- {.*The patient was seen on:s+(d{2}[A-Za-z]{3}d{4}s+d{2}:d{2}).*} $obx_5 {} date] == 1} {
set seen_flag 1
}
The regexp command puts the matching value into {} or ignores it. The next variable is date captured in the first set of parentheses...from left to right.
If the string and the date match by pattern, the variable date would contain what you are looking for.
If you are in an Xlate, you would set xlateOutVals
.Which you coulde then copy it to a field or variable in your translate. I am speculating since I only have limited information.
Jerry Magrann
Jim - thanks for the reply - I am using that as well.
Keith - Many Thanks! I got it working and with your explanation understand a lot better how regexp works and seeing it in action with the match and expressions - I've never used the match and output to a variable like that before, but I'm sure to use it many times over now.
Again, many thanks!
Jerry