Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem extracting data from clipboard using java regexes

Reply
Thread Tools

Problem extracting data from clipboard using java regexes

 
 
spam.eggs.bacon@gmail.com
Guest
Posts: n/a
 
      09-29-2006
Hi,

I need to extract data coming from the system clipboard, process it
(basically parse and transliterate it), and store it in the db. The
clipboard data is basically a CTRL-C of an entire form screen of a
legacy app running on a dumb terminal, and contains multiple <Label>:
<Value> pairs lay down in a typical 1980's form application.

Example:

REG/NO: 1 23456

DATE: 01 01 987

ORGANIZATION: ABC
ORGANIZATION NUM: 123123

BASIC DATA SURNAME: TEST

NAME: TEST


.... etc etc.

I map the clipboard fields using the following code:

HashMap<String,String> clipboardMapping = new
HashMap<String,String>();

clipboardMappings.put("REG_NUM", "\\REG/NO:\\E(.*)$");
clipboardMappings.put("REG_DATE", "\\DATE:\\E(.*)$");
clipboardMappings.put("ORG_NAME",
"\\ORGANIZATION:\\E(.*)\\QORGANIZATION NUM:\\E$");
clipboardMappings.put("ORG_NUM",
"\\QORGANIZATION:\\E.*\\QORGANIZATION NUM:\\E(.*)$");

etc.

Basically, I hunt for literal quotes in the clipboard data and group
the characters that I need following the literals. However, this
approach doesn't work - the regex Matcher doesn't give any matches()
when used against the clipboard.

While I realize what is my problem (using explicit $ on the end of the
regex while the clipboard data doesn't have any explicit endlines
because of the nature of the copy-paste process), I don't know how to
overcome this. For example, using:

"\\QREG/NO:\\E(.*).*"

for extracting the first (REG/NO) field still doesn't give me any
matches, even that logically it should match anything after the first
(.*) group.

I realize that the best approach here woud be to match until the next
field's label (for example, "\\QREG/NO:\\E(.*)\\QDATE\\E.*"), but that
would be a pain because my basic idea is to reuse this regexes in other
forms, where the form layout may vary.

Is there any way I can accomplish these group captures without relying
on the next-field's label?

Thanks for your time.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clipboard - Copy Image To Clipboard Mahsha Javascript 1 06-01-2009 05:06 PM
$clipboard = Gtk::Clipboard.get('PRIMARY')... under windows Dan Bishop Ruby 0 08-26-2008 01:47 PM
clipboard.setContents destroys clipboard.getContents? spunibard@gmail.com Java 2 03-02-2007 07:52 PM
Paste from clipboard when clipboard changes mid script melvynm@gmail.com Javascript 4 12-14-2004 10:59 PM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC ASP .Net 5 09-01-2004 04:49 AM



Advertisments