How can I extract multine data using a regex? ... driving me nuts!!

Hi everyone,
I have a file which I'm interested in extracting information from. Here is a snippet:
CGCNNNNGTAGTC
TAGTCNN
... my goal is to create a regex which extracts out everything beyond the N (on the first line), along with anything on the next line which is not N.
As a result, my desired outcome is "GTAGTCTAGTC"
What I've worked on sofar (for my regex) is:
Pattern p = Pattern.compile("(N[ATGC].*)\\r\\n[ATGC].*N", Pattern.MULTILINE);I've worked on it for sometime now, and am very interested in advice as-to how I can extract my desired information.
Thanks once again,
p.
Edited by: phosse1 on Apr 9, 2009 8:37 PM
Edited by: phosse1 on Apr 9, 2009 8:38 PM

Till one of the regex gurus comes around to shorten the regex by 50% and increase the readability and efficiency by 1000% ;-)import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CrossLineMatcher {
   public static void main(String[] args) {
      String[] inputs = {
         "CGCNNNNGTAGTC\n" +
         "TAGTCNN",
         "CGCNNNNGTAGTC\r\n" +
         "TAGTCNN",
         "CGCNNNNGTAGTC\r" +
         "TAGTCNN",
      String regex = "(?m)(?<=N)([^N]+)(?:$[\\r\\n]+^)([^N]+)(?=N)";
      Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
      for (String input : inputs) {
         Matcher matcher = pattern.matcher(input);
         while (matcher.find()) {
            System.out.println(matcher.group(1)+matcher.group(2));
      System.out.println("=======================");
      regex = "(?m).*?N([^N]+)(?:$[\\r\\n]+^)([^N]+)N.*?";
      for (String input : inputs) {
         System.out.println(input.replaceAll(regex, "$1$2"));
everything beyond the N (on the first line), along with anything on the next line which is not NYou want to express a match for "anything that is not N", use [^N]
[ATGC] means "anything that is A, T, G or C"
db

Similar Messages

  • How can I extract the data from Xstring .

    Hi Gurus ,
    How can I extract the data from a XSTRING  .
    I have to get the data which is filled in the survey form the data is getting saved in form of xstring .
    Someone told me that there is a standard FM for that . but I am not able to find .
    Please reply with the FM in case some one knows about it .
    Thanks in advance .

    The following code works as of 7.0 (in any SAP system):
    FORM XSTRING_TO_STRING USING input TYPE xstring CHANGING output TYPE string.
    TYPES : BEGIN OF ty_struc,
              line TYPE c LENGTH 100,
            END OF ty_struc.
    DATA lt_char TYPE TABLE OF ty_struc.
    DATA length TYPE i.
    length = xstrlen( input ) / cl_abap_char_utilities=>charsize.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer                = input
      tables
        binary_tab            = lt_char.
    CONCATENATE LINES OF lt_char INTO output RESPECTING BLANKS.
    output = output(length).
    ENDFORM.
    Edited by: Sandra Rossi on Mar 30, 2010 12:24 AM

  • How can I extract trading data within sales data

    hi experts,
                    How can I extract trading data (2LIS_46_ITM) with sales data (2lis_11_VAITM) ? I want only one data source and extract data of both data source. I have noticed that many fields are common but other fields are not common.
    Message was edited by:
            rakesh jangir

    Hi ganesh,
                    Thanks for answer. it is correct that Generic is the final solution.
    But is there any other solution if i don't want to create generic data source due to some issues.
    Message was edited by:
            rakesh jangir

  • How can I validate a date using sql

    How can I validate a date using sql or pl/sql
    select to_date('01/01/2009','mm/dd/yyyy') from dual this is a good date
    but how can I check for a bad date
    select to_date('0a/01/2009','mm/dd/yyyy') from dual
    Howard

    William Robertson wrote:
    It'll be complicated in pure SQL, as you'll have to parse out day, month and year and then validate the day against the month and year bearing in mind the rules for leap years. It would be simpler to write a PL/SQL function and call that.Nah, not that complicated, you just need to generate a calender to validate against.
    SQL> ed
    Wrote file afiedt.buf
      1  with yrs as (select rownum-1 as yr from dual connect by rownum <= 100)
      2      ,mnth as (select rownum as mn, case when rownum in (4,6,9,11) then 30
      3                            when rownum = 2 then 28
      4                       else 31
      5                       end as dy
      6                from dual
      7                connect by rownum <= 12)
      8      ,cent as (select (rownum-1) as cen from dual connect by rownum <= 21)
      9      ,cal as (select cen, yr, mn,
    10                      case when ((yr = 0 and mod(cen,400) = 0)
    11                             or (mod(yr,4) = 0 and yr > 0))
    12                            and mn = 2 then dy+1
    13                      else dy
    14                      end as dy
    15               from cent, yrs, mnth)
    16  --
    17      ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    18  --
    19  select case when cal.cen is null then 'Invalid Date'
    20              when not regexp_like(dt,'^[0-9]{1,2}[\/.-_][0-9]{1,2}[\/.-_][0-9]{4}$') then 'Invalid Date'
    21         else dt
    22         end as dt
    23  from dt left outer join
    24               cal on (to_number(regexp_substr(dt,'[0-9]+')) between 1 and cal.dy
    25                   and to_number(regexp_substr(dt,'[0-9]+',1,2)) = cal.mn
    26                   and floor(to_number(regexp_substr(dt,'[0-9]+',1,3))/100) = cal.cen
    27*                  and to_number(substr(regexp_substr(dt,'[0-9]+',1,3),-2)) = cal.yr)
    SQL> /
    Enter value for date_dd_mm_yyyy: a1/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select 'a1/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 01/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '01/02/2008' as dt from dual)
    DT
    01/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2008' as dt from dual)
    DT
    29/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 30/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '30/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 28/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '28/02/2009' as dt from dual)
    DT
    28/02/2009
    SQL> /
    Enter value for date_dd_mm_yyyy: 0a/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '0a/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 00/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '00/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL>

  • How can we store xml data using jsp

    hai,
    Can anyone please explain in brief how to store xml data using jsp. Also if possible please explain by specifying the code.
    regards,
    Praveen Vinnakota.

    [email protected] wrote:
    how can we publish Labview data using the web?
    You could use shared variables and publish them to the network or use data sockets.
    Kudos always welcome for helpful posts

  • How can we publish Labview data using the web

    how can we publish Labview data using the web?
    Dr. Eugene Berman, Moran Kamilyan and Ravit Bar

    [email protected] wrote:
    how can we publish Labview data using the web?
    You could use shared variables and publish them to the network or use data sockets.
    Kudos always welcome for helpful posts

  • How can I extract a dates column from an ascii file

    I am extracting data from an ascii file and the rest of the data is extracted using read from spreadsheet, but the date appears as just the day e.g. 22 for 22nd, how can I get the date, format in ascii is e.g 22/04/2006, can I do this by specifying something at format of read from spreadsheet ? Cheers
    Emily

    Hi,
    I found the other day that there are instructions included inside the Read From Spreadsheet vi on how to modify it slightly to read strings rather than doubles.
    If you drop the Read From Spreadsheet  vi onto the block diagram and double click on it, you will open the front panel for the vi. If you then select the block diagram (for Read From Spreadsheet) you will see an 'instructions' frame below the main 'code', and the 3rd paragraph tells you how to modify the VI to read the spreadsheet as a set of strings rather then doubles. Save the vi as a new filename when you've edited it or you will overwrite the existing vi!
    Using the newly modified vi you can read in your entire spreadsheet, extract the dates as strings, then do any conversion necessary to the other columns of the sheet to change them into the types of value you require (eg doubles).
    I hope this helps.
    Mark
    Applications Engineer
    National Instruments

  • JSObject returns wrong date. How can I extract correct date from digital signature?

    I'm trying to extract name and date from digital signatures by using JSObject in Excel VBA, but JSObject returns wrong date. Year, month, hour and minute are correct, but only day is incorrect.
    Here is my code. I'm using Acrobat 8.1.3.
    Please tell me what's wrong with this code and how I can extract correct date from digital signatures.
    Public Sub sbTest()
    Dim oApp As Acrobat.acroApp
    Dim oPDDoc As Acrobat.AcroPDDoc
    Dim jso As Object
    Dim f As Object
    Dim sig As Object
    Dim strFileName As String
    Set oApp = CreateObject("AcroExch.App")
    Set oPDDoc = CreateObject("AcroExch.PDDoc")
    strFileName = "C:\Test.pdf"
    If (oPDDoc.Open(strFileName)) Then
    Set jso = oPDDoc.GetJSObject
    Set f = jso.getField("Signature1.0")
    Set sig = f.signatureInfo()
    Debug.Print sig.Name
    Debug.Print sig.Date
    End If
    Call oPDDoc.Close
    Call oApp.Exit
    End Sub

    Hi
    You can use TDMS file format to save the data. I have attached a reference Vi.
    On button click you can log the data or remove the case structure and continuous log the complete acquisition data.
    Thanks and Regards
    Himanshu Goyal
    Thanks and Regards
    Himanshu Goyal | LabVIEW Engineer- Power System Automation
    Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
    It Only gets BETTER!!!
    Attachments:
    Data Save in File.vi ‏35 KB

  • How can i extract the data from the jukebox zen h

    Hi,
    my jukebox zen fireware crashed and i extract the hard disk from the player, now, I?m trying to extract the mp3 files from this hd. I?ve connected to the pc via usb external box and my pc recognizes the hard disk and the data inside but i dont know how to extract it, can anyone say me how to do it please ?
    Thanks.

    The hard disk is in a custom format and there's no known method of extracting the data, in the public domain at least.
    Some folks have had luck with both Creative and private services in terms of getting the data extracted, but it'll cost.

  • How can I extract the data from a Real-time Execution Trace ".log" file?

    I would like to get the data for the traces from the Real-time Execution Trace toolkit ".log" file to read in Excel and generate a report.

    Hi Chuck,
    Have you tried reading it into a text or binary file first and then generating a report using the Report Generation VIs?
    Ipshita C.
    National Instruments
    Applications Engineer

  • How can I lock planning data using SEM-BPS Status tracking monitor

    Hi,
    What are the pre-requisites for being able to lock planning data when using certain header characteristics
    in customizing the Status and Tracking System in BPS ?
    I have done the following and expect the locks to be set, but they are not set and the data is still available for planning :
    1. Assigned the 0COMPANY hierarchy to a subplan with a planning area which has header characteristics : VERSION and CALYEAR.
    Header  characteristic customization is as follows :
    CALYEAR = 2005
    VERSION = V1
    2. Have set the status of all nodes in the hierarchy to 'approved' .
    3. I execute a Web planning interface for this planning area with a selection of a 0COMPANY within this hierarchy, PLANYEAR = 2006, CALYEAR = 2005 and expect the plan to be locked but its not.
    Could someone kindly explain why ?
    Regards.
    PS : Hope the scenario is clearly explained.

    Hello Anuradha,
    The plan data should be locked after the status is switched if
    - the package selection used in the planning function or planning layout is entirely contained in the header selection
    - you do not access the plan data via a multi area
    - the user does not have the authorization "STS_SUP" (super user).
    It is important to note that the characteristic used to define the hierarchy is not used in the locking. The characteristic is only used to define the hierarchy.
    In your example only the characteristics year and version are relevant for locking as these are the only ones used in the header selection. The data should be locked if the package selection is year = 2005 and version = V1. If you have a selection like year = 2005 and version = V1, V2 then the data is not locked as the selection is not completely contained in the header selection. Note that even if you only use version V1 in your selection but if you use a planning layout that has V2 in a comparison column then the system will enlarge the selection and data would not be locked.
    Best regards,
    Gerd Schoeffl
    SAPNetWeaver RIG BI

  • How do I extract the data of Variant configuration into internal tables

    Hi Experts,
    How can I extract the data of variant configuration into an internal tables while preparing the report.
    Thanks,
    bsv.

    Hi i´m not a "Expert.." but may I can help you:
    CUCB_GET_VALUES_FROM_INSTANCE
    Example:
    Instance =  MARA-CUOBF  or
    Instance = lips-cuobj
    Result is the data of the Variant tables.
    I need that for a simple report to evaluate customer & and his Variants......
    Robert

  • How can i extract data strings (temp. press. rel.hum etc) using a Virtual interface through an RS-232 connection​?

    How can i extract data strings (temperature, pressure, relative humidity etc) using a Virtual interface through an RS-232 connection?

    Try this.  It is in LV 8.5.
    Note the double % in the format string.  This is so the % in the input string is treated as a percent rather than a code.
    You may also have to work with the line feed characters in case they are different in the string coming in compared to how the string shows up in the web browser.
    Message Edited by Ravens Fan on 02-12-2008 10:19 PM
    Attachments:
    Example_BD.png ‏4 KB
    Untitled 11.vi ‏9 KB

  • How can i extract data from oracle table  to flat file or excel spread shee

    Hello,
    DB Version is 10.1.0.3.0
    How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
    Regards,
    D

    Here what I did
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 80
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET VERIFY OFF
    SET HEADING OFF
    SET MARKUP HTML OFF SPOOL OFF
    Sql> SPOOL bing
    select * from -------;
    SPOOL OFF;
    I do not see file.
    I also tried
    Sql> SPOOL /tmp/bing
    select * from -------;
    SPOOL OFF;
    But still not seeing the fie,

  • How can i extract using while the time from the string ?

    First time how can i extract the time as string ?
    And second how can i extract the time as DateTime.Now ?
    public static void ExtractDateTime()
    htmltoextract = new Uri("http://test.com");
    client = new WebClient();
    f = client.DownloadString(htmltoextract);
    client.Dispose();
    int index = 0;
    while (index != -1)
    int t = f.IndexOf(firstTag);
    int g = f.IndexOf(lastTag);
    a = f.Substring(t + firstTag.Length, g - t - 8);
    The string look like this: thisisateststring201309202145andthenextimeinthestringis201309202130andthelastofthisexampletimeinthisstringis201309202115
    What i need to do is first time to extract the time as string to a List<string> like this:
    index 0 201309202145
    index 1 201309202130
    index 2 201309202115
    The second time to extract the times as this time format: YYYYMMDDhhmm and also to add the times to a List.
    First time and second time i mean first example and second example. To use my code but first time to extract it as strings second example as the format of YYYYMMDDhhmm
    And i need to use the while and indexof and substring in this cases.

    Is the region always going to be "eu" or are you going to have more than one region.  Since you are reading a string DateTime from different timezone than the computer you are reading the data you have to convert to a different timezone. 
    It looks like you have at least 'is' and 'eu' for regions.  I don't know what offsets you need so try something like this.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Globalization;
    using System.IO;
    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    string input = File.ReadAllText(@"c:\temp\test.txt");
    string pattern1 = @"imageUrls = \[[^\]]*\]";
    Regex ex1 = new Regex(pattern1, RegexOptions.Singleline);
    string pattern2 = @"region=(?'region'[^&]*)&time=(?'time'\d{12})";
    Match match1 = ex1.Match(input);
    Regex ex2 = new Regex(pattern2, RegexOptions.Singleline);
    MatchCollection matches2 = ex2.Matches(match1.Value);
    IFormatProvider provider = CultureInfo.InvariantCulture;
    List<DateTime> dateTime = new List<DateTime>();
    foreach (Match match2 in matches2)
    string region = match2.Groups["region"].Value;
    DateTime dt = DateTime.ParseExact(match2.Groups["time"].Value, "yyyyMMddHHmm", provider);
    switch (region)
    case "eu" :
    dt.AddHours(1);
    break;
    case "is":
    dt.AddHours(-1);
    break;
    dateTime.Add(dt);

Maybe you are looking for

  • SetTnxNoSync: No disk access before a sync

    Hello, I try to use Berkeley DB to store a lot of KV.The software must index a lot of data (put/get) and then wait for resquest from user (get) or new information for the index (put/get). During the big indexing phase, It should be great if Berkeley

  • So I deleted everything off of my iphone. The more I delete, the larger the "Other" section gets. How do I resolve this?

    So at first on my 8GB iphone I had about 10 apps, 2.5 gigs of music, and a lot of pictures. I have about 2.2 gigs being taken up by "Other" when I synced it to itunes. I deleted all of my messages, all of my emails, cleared all cache & my browsing hi

  • Me29n

    i wanna release standard purchase order i cant not find release strategy tab in header of document level while iam using me29n t code can anyone can answer this ?

  • File with Same Name

    I'm trying to backup my Library to an external hard disk. Anyhow, when I moved to iPhoto I kept a copy of all my photos in their original folder structure and that copy exists on the external hard drive. When I drag my Library to the external I get a

  • When using SEGW / Mapping GetEntitySet  to function call , is $filter implemented automatically?

    Hey everyone Im trying to understand if im missing out on something or just misunderstanding things. i've created an entity, and a function. calling this entity using standard key filter works (i.e /FlightSet(0001), but when using /FlightSet?$filter=