Problem extracting data from clipboard using java regexes

Discussion in 'Java' started by spam.eggs.bacon@gmail.com, Sep 29, 2006.

  1. 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.
     
    , Sep 29, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    792
  2. Dan Bishop
    Replies:
    0
    Views:
    262
    Dan Bishop
    Aug 26, 2008
  3. Replies:
    4
    Views:
    305
    Randy Webb
    Dec 14, 2004
  4. Mahsha

    Clipboard - Copy Image To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    1
    Views:
    645
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
  5. Mahsha

    Clipboard - Copy Text To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    3
    Views:
    688
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page