Problem extracting data from clipboard using java regexes

G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top