Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CR 10/11 - Regular expressions in formulae/functions

Status
Not open for further replies.

shera4111

Programmer
Apr 12, 2006
27
CA
Hello all,

Anyone know if you can use regular expressions in formulae/functions?

Basically I have a memo field with multiple timestamps, along with some other info. I want to get hold of all the info after the last timestamp, so ideally I'd like to match on the regex for the timestamp.

Thx,
shera4111
 
What do you consider a regular expression?

You can use INSTR, REVINSTR and LIKE if that's what you mean.

If you post the format of the data and what you need we can offer specifics.

If you have a common delimiter then a SPLIT function might work as well.

-k
 
Thanks K,

Here's what the timestamp looks like:
06/06/2006 1:23:54 PM

What I'd like to do is this:
NumberVar last_timestamp_pos = instrrev({string_field}, date_format)

In Java, I'd do something like this for the regex (apologies to any java gurus who see this and wince... it's been a while since I wrote a regex):
(??\/??\/?? ?:??:?? PM|AM)
|
(??\/??\/?? ??:??:?? PM|AM)
And then feed that into the insstrrev function... idea is to find the last occurrence of the timestamp in the string field.

Maybe LIKE is what I'm looking for here... how do the wildcards work for that?

shera4111

 
Yeah, Crystal's string handling is far more primitive.

A shame you didn't give an actual example of the last string you need to extract instead of just the timestamp itself.

What I was hoping to see was something like:

06/06/2006 1:23:54 PM:

So that we might key off of the AM/PM and a colon using a SPLIT and a replace, as in:

whileprintingrecords;
stringvar array MyMemo :=split(
replace({table.field},"AM:","PM:"),"PM:");
MyMemo[ubound(MyMemo)]

Again, posting a reasonable example will expedite things, you shouldn't be shy about posting the actual format of your data, it doesn't take much longer to be thorough the first time and given that you appear to be an advanced coder, you should understand this basic requirement.

-k
 
Thanks K again,

I thought I'd been clear enough on the data format... so my apologies for not giving you enough detail. Here's a longer example of what would be found in that field. As you can see, the timestamp is embedded inside...(hyphens just for clarity of start/end):
------------------------------------------------
05/01/2006 1:23:54 PM
This is the first worklog entry in this ticket

06/06/2006 1:23:54 PM
This is the second worklog entry in this ticket
------------------------------------------------

I would like a function that will return:
This is the second worklog entry in this ticket

I will try using split and replace together... might just do the trick. :)

shera4111
 
To answer the direct question: Crystal doesn't support regular expressions. You can create a UFL (User Function Library) that would add that functionality...

To answer the specific requirement, looks like this can be achieved using regular string functions in Crystal.

- Ido



Visual CUT & DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top