priPrinter: Regular expressions - priPrinter

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Regular expressions

#1 User is offline   Hans 

  • Newbie
  • Pip
  • Group: Senior Members
  • Posts: 2
  • Joined: 21-February 14

Posted 21 February 2014 - 06:53 AM

Hi,

does the scripting engine support regular expressions?

I need to extract some data from the document without knowing
the exact position of them (the position is changing from document
to document).

GetText() without arguments returns someting like this:

...
Angebot
Belegnummer2014-30004
11.02.2014
BearbeiterHansi Mueller
Datum
Bitte bei allen Rückfragen angeben !
Ihre UStIDNr
KundennummerD200124
@@NMR 0123-45678-9@@
Pos.Artikelnr.Menge Einzelpreis GesamtpreisMESC TerminBezeichnung
...

I need to extract the strings "2014-30004", "D200124" and "0123-45678-9".

The first two have a known prefix, the last one is enclosed in "@@NMR ....@@".

It would be simple enough with regular expressions, but I have not found a
soulition within the current scripting capabilities of priPrinter...

Maybe you have a hint for me?
0

#2 User is offline   Alex 

  • Administrator
  • Group: Administrators
  • Posts: 238
  • Joined: 28-February 10
  • LocationHungary

Posted 21 February 2014 - 09:41 AM

Hi Hans,

Thank you for asking.

No, regular expressions are not supported for now. They can be added, no technical problem here, but right now - no. Sorry.
However this particular situation can be solved quite easy. See sample below.

SearchString is the main function, it will return NULL if string is not found. Rest part is just for testing.



function SearchString(text,start,end)
{
	local index=text.find(start);
	if(index){
	index+=start.len();
	local rindex=text.find(end,index);
	if(rindex){
		local str=text.slice(index,rindex);
		return str;
	}
}
}

local text="Angebot\nBelegnummer2014-30004\n11.02.2014\nBearbeiterHansi Mueller\nDatum\nBitte bei allen Rückfragen angeben !\nIhre UStIDNr\nKundennummerD200124\n@@NMR 0123-45678-9@@\nPos.Artikelnr.Menge Einzelpreis GesamtpreisMESC TerminBezeichnung";

local str=SearchString(text,"Belegnummer","\n");
if(str)
	print(str+"\n");
else print("Not Found\n");

str=SearchString(text,"Kundennummer","\n");
if(str)
	print(str+"\n");
else print("Not Found\n");

str=SearchString(text,"@@NMR ","@@");
if(str)
	print(str+"\n");
else print("Not Found\n");

0

#3 User is offline   Hans 

  • Newbie
  • Pip
  • Group: Senior Members
  • Posts: 2
  • Joined: 21-February 14

Posted 21 February 2014 - 05:02 PM

Hi Alex,

thanks for your suggestion - it looks very promising and I'll give it a try
next week! Though support for regular expressions would be nice, too ;-)

Have a great weekend,
Hans
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users