Extract data with RT::Extension::ExtractCustomFieldValues


#1

Hi,
It drives me crazy. Anyone how uses it please help me.
In a nutshell:
I get series of letters which contains the following string : Birth Date: xx/xx/xxx (<- in this particular format)
For some reasons the command :

Birth Date|Body|Birth Date: qr/^(?:(?:(?:0?[13578]|1[02])(/|-|.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(/?|-|.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:(?:0?2)(/?|-|.)(?:29)\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[24 68][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(/?|-|.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/msp

does not extract the date although it must (i’ve checked using a Perl application)

What could be the problem with ?

Please help me!
Thanks.


#2

Are you using

DD/MM/YYY
or
MM/DD/YYY?

Why the 3 digit year? (years since 1900?)


#3

Well, should be DD/MM/YYYY
I don’t see YYY
Can you explain please ?


#4

You had written

Birth Date: xx/xx/xxx

which looked like you were using a 3 digit year…

I tried

perl -e '$date="Birth Date: 22/11/1970"; $regex = qr/^(?:(?:(?:0?[13578]|1[02])(/|-|.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(/?|-|.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:(?:0?2)(/?|-|.)(?:29)\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[24 68][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(/?|-|.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/msp; @parts=$date =~ $regex; print join("/n", @parts)'

and got

Unmatched ( in regex; marked by <-- HERE in m/^(?:(?:(?:0?[13578]|1[02])( <-- HERE / at -e line 1.

I would highly suggest using the /x modifier and adding some white space and perhaps even some comments there.

Also… I wonder if regex is the wrong tool for the job? If you extract

my ( $date ) = /Birth Date: (.*)/

Then use split to grab $day, $month and $year

( $day, $month, $year ) split( '/', $date );

Then you can test $day, $month and $year individually… or even better, use Date::Parse.


#5

Well, that’s basically what i’m trying to achieve.
RT gets a letter containing a string

Birth date : xx/xx/xxxx

BUT, i can’t put it into a custom field.
the plugin is completely ignoring the regexp, it only puts the 2 first numbers.
How can i fix it without going deep into Perl?


#6

According to the RT::Extension::ExtractCustomFieldValues documentation the format is:

<cf-name>|<Headername>|<MatchString>|<Postcmd>|<Options>

Your line appears to have a match string that is looking for lines in the Body that contain ‘Birth Date: qr/’ and then the regexp text. But the <MatchString> section of the template already is a regexp - you don’t need the ‘qr//’ bit.

Your regexp also has vertical bar characters (|) which are the separators in the template. You might want to use the “Separator” directive in the template to change this to a pattern that isn’t in your regexp (see example 6 in the documentation).

Have you tried something simple to start with such as:

Birth Date|Body|Birth Date:\s+(.+)$|

If that works, build up the regexp you want from there, or do as @Barton_Chittenden and use the Postcmd section of the template to do date seperation and validation, rather than in the complex (and frankly rather unreadable) regexp.


#7

Thanks for your advice. Will try it the way you described
I’m just curious whether it is me or the plugin playing a bad trick on me :slight_smile:


#8

works super fine :smiley:
the only unambiguous thing now is that if i open ticket details i see this
Capture

how can it be fixed?


#9

not very handy as i want to further process this data , i think it might be possible to get rid of this


#10

Have you tried tweaking the regexp to make it more specific so that it doesn’t match the HTML bits at the end? Something like:

Birth Date|Body|Birth Date:\s+(\d+/\d+/\d+).*$|


#11

Yeah, however looks like it appends it after it is processed by the plugin. I’ve cleaned all invisible symbols and it is fine now. but i can’t confirm it 100% sure, will play around and let you know.