Regular expression help please. (extractin​g a string subset between two markers)

I haven't used regular expressions before, and I'm having trouble finding a regular expression to extract a string subset between two markers.
The string;
Header stuff I don't want
Header stuff I don't want
Header stuff I don't want
Header stuff I don't want
Header stuff I don't want
Header stuff I don't want
ERRORS 6
Info I want line 1
Info I want line 2
Info I want line 3
Info I want line 4
Info I want line 5
Info I want line 6
END_ERRORS
From the string above (this is read from a text file) I'm trying to extract the string subset between ERRORS 6 and END_ERRORS. The number of errors (6 in this case) can be any number 1 through 32, and the number of lines I want to extract will correspond with this number. I can supply this number from a calling VI if necessary.
My current solution, which works but is not very elegant;
(1) uses Match Regular Expression to the return the string after matching ERRORS 6
(2) uses Match Regular Expression returning all characters before match END_ERRORS of the string returned by (1)
Is there a way this can be accomplished using 1 Match Regular Expression? If so could anyone suggest how, together with an explanation of how the regular expression given works.
Many thanks
Alan
Solved!
Go to Solution.

I used a character class to catch any word or whitespace characters.  Putting this inside parentheses makes a submatch that you can get by expanding the Match Regular Expression node.  The \d finds digits and the two *s repeat the previous term.  So, \d* will find the '6', as well as '123456'.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

Similar Messages

  • Regular Expression Help Please?

    Hi
    I'm trying to get my head round regular expressions in find
    and replace,
    it's a slow process for me!
    I have this -
    <a
    href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=http://www.website-ad dress.com"
    and I'm trying to change it to this -
    <a
    href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=http://www.website-ad dress.com&email="
    I was trying first of all with a *.*, but couldn't work out
    how to tell it
    where the code ends?
    They are hundred of pages like this, all with different
    website-addresses.
    After I have changed all the pages to the new code, I then
    will need to copy
    and paste an different email address to the end of each line,
    to each page.
    Unless anyone knows a way of automating that?
    Hope someone can point me in the right direction?
    Many thanks, Craig.

    Hi David
    Many thanks for all that and the detailed descriptions.
    I will be working through it all again tomorrow, so will put
    your info to
    the test! lol
    As for partially building the email addresses, I think that
    would be too
    much,
    as the emails are all over the place, some have their own
    domain, other use
    hotmail, Yahoo etc.
    Some even have they own domain for their website and a free
    one for the
    email address.
    They are all Hotels, B&B' & Cottages etc.
    Hopefully all your hard work will help me a step closer to
    understanding it
    all.
    Many thanks again,
    Craig.
    "David Stiller" <[email protected]> wrote in
    message
    news:[email protected]...
    > Craig,
    >
    >> You do have that correct David, thanks.
    >
    > Okay.
    Regex is as much an "exact science" as it is an "art
    > form" -- which isn't to say I'm a regex artist; I just
    love the
    > technology -- but I mention this because I made the
    following assumption
    > in order to keep the pattern relatively simple: your
    href values are all
    > quoted in either single or double quotes. Such as, for
    example, the
    > following sample HTML ...
    >
    > <body>
    > <a
    > href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.sample.com">asfd< /a>
    > <a
    > href='
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.example.net'></a>
    > <a
    > href="
    http://www.forms.mydomainname.com/cgi-bin/urltracker/tracker.pl?site=www.company.com"></a>
    > </body>
    >
    > In the Find field, enter this pattern ...
    >
    > (tracker\.pl\?site=.*?)(["'])
    >
    > ... and in the Replace field, enter this pattern ...
    >
    > $1&email=ADDRESS$2
    >
    > Then carefully use your Find Next and Replace buttons to
    step through
    > your code. The above will add &email=ADDRESS to your
    HTML in all the
    > right places. I chose that because ADDRESS is easy to
    select by double
    > clicking, which should facilitate your replacing it.
    >
    >
    > Let's step through the patterns.
    >
    > (tracker\.pl\?site=[^"']*?)(["'])
    >
    > This looks for the phrase "tracker.pl?site=" (without
    quotes) followed
    > immediately by a "non-greedy" match of any character
    that isn't a single
    > or double quotation mark, followed immediately by either
    a single or
    > double quotation mark. I took , which I took to be a
    safe, short "hook"
    > into the string we need. I split this pattern into two
    sections, grouped
    > by parentheses. This allows us to refer to the first
    part of the match
    > (everything but the closing quotation mark) as group 1,
    and the second
    > part (the closing quotatin mark) as group 2. This is
    like storying values
    > with your calculator's M (memory) button.
    >
    > $1&email=ADDRESS$2
    >
    > Here, we refer to group 1 and follow it with the phrase
    > "&email=ADDRESS" (without quotes), followed again by
    group 2.
    >
    > Now, in theory, we could use the domain name of each
    unique site to at
    > least partially build the email address. That would get
    you even closer
    > to your goal. To do so, I'd need even more detail from
    you, such as the
    > kinds of domains you have (how many sub domains are
    probable, etc.).
    >
    >
    > David
    > stiller (at) quip (dot) net
    > Dev essays:
    http://www.quip.net/blog/
    > "Luck is the residue of good design."
    >

  • Finally I dont understand how to compound regular expressions, help please

    I have read a lot of information about it, but .... I still do not understand how to make compound expresions ....
    How must I use [ ] ?
    Please three examples :
    I want to search :
    - any character but nothing of "abcd"
    - any character but no 'dot' at any position
    - any character but no 'dot' at position 4
    Any good tutorial ?
    Thank you

    The way you have used the word 'search' create some uncertainty in my mind as to what you are asking for. I suspect that what you really want is a 'true' or 'false' that a given string matches some pattern. There are other ways to do this but ...
    "any character but nothing of "abcd" " then use Matcher.matches() using regex "[^abcd]*" .
    "any character but no 'dot' at any position" then Matcher.matches() using regex "[^.]*" .
    "any character but no 'dot' at position 4" then Matcher.matches() using regex "(?!.{3}\\.)" .
    Edited by: sabre150 on Aug 5, 2010 8:50 AM
    Sodding forum markup!

  • Regular Expression Help

    I need help writting a regular expression that will match the following strings:
    1+1,1+(1+1),((1+1)+(1+1)),1+(1+(1+1)). Basically one that will match an arithmetic expression (operands limited to 1's and operators to '+' sign) with or without correctly matched parentheses. Have'nt had much luck so far. Any input will help. thanks

    okay, you asked for it:
    [1+()]+
    it will only match those string but it will tell you nothing about syntactically correct expressions. This is because these types of expression are not "regular" and cannot be properly parsed using regular expressions.

  • Phone number Regular expression Help

    Hi,
    I am trying to validate phone number using regular expression.
    The format shoud be either of the two given below. It should not
    accept phone number of any other format other than the once given below.
    I tried out the following regular expression
    pn.matches("[\p{+}][0-9]+ ")
    but it accepts alphabets too(which is wrong).
    How do i check if the phone number is of the following format(OR condition).
    0401234567
    +358501234567
    Any help would be kindly appriciated.
    Thanks
    Sanam

    There will probably be much more constraints on you phone numbers, but here's a start:String[] numbers = {"0401234567",      // should be ok
                        "040123456",       // wrong, one number too little
                        "+358501234567",   // should be ok
                        "+3585012345670",  // wrong, one number too much
                        "+35850123456"};   // wrong, one number too little
    String regex = "\\+[0-9]{12}"+         // a + sign, followed by 12 numbers
                   "|"+                    // OR
                   "0[0-9]{9}";            // a zero, followed by 9 numbers
    for(String n : numbers) {
      System.out.println("Is "+n+" valid? "+n.matches(regex));
    }

  • Regular expression to check the sequence of strings

    HI,
    I am validating an EDI document like as follows
    ISA*XX*XXXXXXXXXXXXXXX*XX*XXXXXXXXXXXXXXX*030130*0912*~IEA*1*000005900~
    I need to create a regular expression which checks ISA should always occur before IEA.
    Please help me if you have any hints.
    Thanks.

    Thanks.I had taken that into consideration.
    But using regular expression I could say
    ISA* only once
    IEA* only once
    And
    ISA before IEA
    Any hints how to specify "before"/sequence using Regular expression ?
    I agree sometime using basic String operation we can do this.

  • Regular expressions help

    I'm using a RegExp class (http://www.jurjans.lv/flash/RegExp.html) to do some regular expression in AS2. But I'm not very good at it.
    var str:String="What if there are other variables, such as possible <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a> which could explain at least some of the relationship between the two variables? Here <a href='' target='_blank'>is another link</a>.\n<a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>"
    var reg1:RegExp = new RegExp("<a.*gloss.*href=[\'\"]?([^\\\'\">]+)>+(.*</a>)", "ig");
    var obj:Object = reg1.exec(str);
    while (obj != null) {
              for(var a in obj){
                        if(!isNaN(a)){
                        trace(a+": "+obj[a]);
              trace(newline);
              obj = reg1.exec(str);
    And this traces:
    2: <b>confounding variables</b></a>
    1: asfunction:_root.handle, confounding variables'
    0: <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a>
    2: confounded variables</a>
    1: asfunction:_root.handle, confounding variables'
    0: <a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>
    I'm trying to get the href and the "friendly link" part of the anchor tag (but only for anchors that have a class of gloss).
    As you can see I'm almost there, but I'm getting the extra </a> and the extra ' on the two examples. I tried putting the ) before the </a> but that just broke it. (Of course that could be because this class doesn't work properly, but I'm guessing that isn't the case.)
    Anybody really good with regular expressions who can help me out?

    Looks like there is a "greedy" bug with the () in that AS2 implementation.
    I also have a problem the expression matching not the next occurance of the closing </a> but the final one.
    Anybody have any ideas of other ways to do this?

  • Regular Expression help required

    {color:#000000}Hi....
    I am having a product table in oracle with products like CZS20T and CZSS30T and so on....
    But for printing on the invoice we need only the product name without the micron thickness like CZS and CZSS{color}{color:#000000}
    I tried regular expression with....."select regexp_substr('CZSS20T','([[:digit:]]{2})') from dual"
    {color}
    and the result was "20"*...*
    But I cant figure out how to use regular expression to get only the product name.
    Maybe there is another way without using Regular exp...
    Please help....

    regexp_substr (prod, '[[:alpha:]]*')and an example:
    SQL> with x as
      2  ( select 'CZS20T' prod from dual union all
      3    select 'CZSS30T' from dual union all
      4    select 'A10CSD' from dual
      5  )
      6  select prod
      7       , regexp_substr (prod, '[[:alpha:]]*')
      8    from x
      9  ; 
    PROD    REGEXP_SUBSTR(PROD,'[[:ALPHA
    CZS20T  CZS
    CZSS30T CZSS
    A10CSD  A
    SQL> Edited by: Alex Nuijten on Jan 27, 2009 8:52 AM

  • Regular Expression to capture user's input string

    I am writing a helper class to split user input string into String array according to the following pattern:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class TestDelimiter {
    static Pattern p = Pattern.compile("(.*?)[,;]{1}");
    static Matcher m;
        public static void main(String[] args) {
            String input = "AAA111111,BBB222222;CCC333333";
            m = p.matcher(input);
            while(m.find()){
                String output = m.group(1);
                System.out.println(output);
    }Output:
    AAA111111
    BBB222222My question is, how can I modify the regular expression string so that the CCC333333 (last element) can also be included?

    roamer wrote:
    Ok, let's don't argue on this point.Who's arguing?
    I think I got the answer. For simplicity, I can just manually add a ";" or "," string after each user input. Just like:You never said anything about that before. You asked how to split "AAA111,BBB222;CCC333" into its components and you were given a correct answer.
    Maybe you should rephrase your question including this added requirement. Do you need to have the separator included in the final outputs or why do you want to suddenly add things to user input?

  • REGULAR EXPRESSION FIND PLEASE  ;(

    HI FORM
    I have the following documents with the content
    doc1 = "ELECTRONICS DIGITAL CAMERA"
    doc2 = "ELECTRONICS DIGITAL CAMERA ACCESSIORIES"
    doc3 = "ELECTRONICS DIGITAL CAMERA OPTICS "
    Using regexpression I would like to get only 2nd document ONLY which has the content
    "ELECTRONICS DIGITAL CAMERA ACCESSIORIES"
    How to Achieve this
    Karthik

    You can try this one: ((digital|camera|accessories)[\\s]*)+
    Explainations:
    (digital|camera|accessories) - this group matches any of the 3 words
    [\\s] matches a space character [\\s]* matches any number of spaces
    ((digital|camera|accessories)[\\s]*) - this group matches any of the 3 words, optionnally followed by spaces
    ((digital|camera|accessories)[\\s]*)+ - matches any sequence of 3 words, seperated by spaces
    NOTES:
    - this regular expression matches "digitalcameraaccessories" because the * operator accepts 0 occurences.
    If you want to avoid this situation, change the * to a+, but you will have to append a space to the searched string
    in order to make the pattern match.
    - this regular expression will also match "digital digital camera" because there is no unicity checking.
    Hope this helped,
    Regards.

  • Regular expression help to solve sys_refcursor for a record

    In reference to my thread Question on sys_refcursor with record type , I thought it can be solved differently. That is:
    I have a string like '8:1706,1194,1817~1:1217,1613,1215,1250'
    I need to do some manipulation using regular expressions and acheive some thing like
    select * from <table> where
    c1 in (8,1)
    and c2 in (1706,1194,1817,1217,1613,1215,1250);Is it possible using regular expressions in a single select statement?

    Hi,
    Clearance 6`- 8`` wrote:
    Your understanding is absolutely correct. But unfortunately it did not work Frank.
    SQL> SELECT COUNT (*)
    2    FROM (SELECT sp.*
    3            FROM spml sp, spml_assignment spag
    4           WHERE sp.spml_id = spag.spml_id
    5             AND spag.class_of_svc_id = 8
    6             AND spag.service_type_id IN (1706, 1194, 1817)
    7             AND spag.carrier_id = 4445
    8             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    9             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    10             AND spag.unit_id = 5
    11             AND sales_org_id = 1
    12          UNION ALL
    13          SELECT sp.*
    14            FROM spml sp, spml_assignment spag
    15           WHERE sp.spml_id = spag.spml_id
    16             AND spag.class_of_svc_id = 1
    17             AND spag.service_type_id IN (1217, 1613, 1215, 1250)
    18             AND spag.carrier_id = 4445
    19             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    20             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    21             AND spag.unit_id = 5
    22             AND sales_org_id = 1);
    COUNT(*)
    88
    SQL> SELECT COUNT (*)
    2    FROM spml sp, spml_assignment spag
    3   WHERE sp.spml_id = spag.spml_id
    4     AND spag.carrier_id = 4445
    5     AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    6     AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    7     AND spag.unit_id = 5
    8     AND sales_org_id = 1
    9     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    10                      '(^|~)' || spag.class_of_svc_id || ':'
    11                     )
    12     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    13                      '(:|,)' || spag.service_type_id || '(,|$)'
    14                     );
    COUNT(*)
    140
    SQL> Edited by: Clearance 6`- 8`` on Aug 11, 2009 8:04 PMJust serving what you ordered!
    Originally, you said you were looking for something that produced the same result as
    where   c1 in (8, 1)
    and      c2 in (1706, 1194, 1817, 1217, 1613, 1215, 1250)that is, any of the c1s could be paired with any of the c2s.
    Now it looks like what you want is
    where     (     c1 = 8
         and     c2 IN (1706, 1194, 1817)
    or     (     c1 = 1
         and     c2 IN (1217, 1613, 1215, 1250)
         )that is, c1=8 and c2=1250 is no good; neither is c1=1 and c2=1706.
    In that case, try
    WHERE     REGEXP_LIKE ( s
                  , '(^|~)' || c1
                         || ':([0-9]+,)*'
                         || c2
                         || '(,|~|$)'
                  )

  • Regular Expressions help needed.

    Hi,
    I have lines like
              <div id="contentSub">         26
              /*]]>*/</style>         27
    <ul>         30
    Dylan is gay         36
    var wgNamespaceNumber = 0;         41You see every line is contained a string plus some white spaces then plus a number.
    How to retrieve the strings?
    Such that becomes
    <div id="contentSub">
              /*]]>*/</style>
    <ul>  
    Dylan is gay   
    var wgNamespaceNumber = 0;  And also get the number by a regular expression
    26
    27
    30
    36
    41Thanks

    I believe that
    "^(.*)\\s+(\\d+)$"would do the trick. Pick the two groups out from the Matcher.

  • Regular expressions HELP :S

    Hi all,
    I am trying to use the pattern and matcher to check that someone has entered a double in the form of 0000.00 where the first part can be any amount (and can exceed four digits) but it must be followed by a decimal point and two further digits. Using focus lost I wanted to clear the input if it is incorrect and disable the ADD button which allows them to proceed.
    Below is my code, the first part for moduleCode works fine, but I can't get anything from the tuitionFee bit, and I'm guessing its my regular expressions??
         public void focusLost (FocusEvent e)
         if (e.getSource () == moduleCode)
         Pattern p = Pattern.compile("[A-Z][A-Z][A-Z][0-9][0-9][0-9]");
              Matcher m = p.matcher(moduleCode.getText ());
              if(!m.matches())
                   moduleCode.setText("");
              error.setText ("PLEASE ENTER 3 UPPERCASE LETTERS FOLLOWED BY 3 DIGITS");
              add.setEnabled (false);     
         if (e.getSource () == tuitionFee)
              Pattern q = Pattern.compile ("[0-9]+?.[0-9][0-9]");
              Matcher d = q.matcher(tuitionFee.getText ());
              if(!d.matches())
                   tuitionFeeCode.setText("");
         add.setEnabled ();     
         }

    Thanks very much for the reply
    I tried the following
         public void focusLost (FocusEvent e)
            if (e.getSource () == moduleCode)
              Pattern p = Pattern.compile("[A-Z][A-Z][A-Z][0-9][0-9][0-9]");
               Matcher m = p.matcher(moduleCode.getText ());
               if(!m.matches())
                   moduleCode.setText("");
                     error.setText ("PLEASE ENTER 3 UPPERCASE LETTERS FOLLOWED BY 3 DIGITS");
                     add.setEnabled (false);     
            else if (e.getSource () == tuitionFee)
                    Pattern q = Pattern.compile ("[0-9]+\\.[0-9][0-9]");
                    Matcher d = q.matcher(tuitionFee.getText ());
                    if(!d.matches())
                     tuitionFee.setText("");
                     error.setText ("PLEASE ENTER THE VALUE IN POUNDS FOLLOWED BY A DECIMAL, THEN THE VALUE IN PENCE");
                   add.setEnabled (false);     
         }However, it still had the same result. When I left the text field the input remained there, whereas it should have cleared if functioning properly?
    thanks

  • Regular expression breaks with \00 in input string

    I wrote the following code to illustrate the problem.
    Clearly the match should occur in both cases, but it does not occur if \00 is in the input string (within the < > ).
    I am not even searching for \00 or \01. This makes the regular expression match rather useless if you have text that contains data in hex form. I am using Labview 8.2. Is this a known bug? Is there a work around?
    Tammo
    Message Edited by Tammo on 03-06-2008 12:26 PM
    Message Edited by Tammo on 03-06-2008 12:26 PM
    Attachments:
    RegEx1.vi ‏56 KB
    BlockDiagram1.jpg ‏18 KB
    FrontPanel1.jpg ‏18 KB

    There was a brief discussion on this not too long ago.

  • Regular expression help needed

    Hello experts,
    I am looking to implement a search & replace regular expression
    my regular expressions are as follows:
    search regular expression = (test\\s+--\\s*)?this is a test(.*)?
    replace regular expression = (new) brand new test$2
    i.e. The results I require are
    case 1
    input string = test -- this is a test 1999
    correct result = (new) brand new test 1999
    or (since I require the regular expression to be optional)
    case 2
    input string = this is a test
    correct result = brand new test
    How do I implement this using pattern and matcher? Sample code would be useful
    I am having difficulties because matcher.appendReplacement will always replace because my regular expressions are optional. (which is incorrect)
    i.e. I am getting the following incorrect result ((new) is being appended)
    input string = this is a test
    incorrect result = (new) brand new test
    At the moment my non working code is
    StringBuffer sb = new StringBuffer();
    Pattern pattern = Pattern.compile("(test\s+--\s*)?this is a test(.*)?");
    Matcher matcher = pattern.matcher("this is a test");
    if(matcher.find())
    matcher.appendReplacement(sb, "(new) brand new test$2");
    String result = sb.toString();
    System.out.println(result);
    }In the above scenario I want the output to be 'brand new test' without the (new) because the input string did not contain 'test --'
    Hope this makes sense
    Thanks

    For example: StringBuffer sb = new StringBuffer();
    Pattern pattern = Pattern.compile("(test\s+--\s*)?this is a test(.*)");
    Matcher matcher = pattern.matcher("this is a test");
    if(matcher.find())
      matcher.appendReplacement(sb, ""); // copy everything before the match
      if (matcher.start(1) != -1)
        sb.append("(new) ");
      sb.append("brand new test");
      sb.append(matcher.group(2));
    matcher.appendTail(sb); // copy everything after the match
    System.out.println(sb.toString()); Because the first group is optional, you need to find out whether it participated in the match before you add the "(new) " bit. The second group doesn't need to be optional because (1) the subexpression with the group can match nothing, and (2) you don't need to perform a different action depending on what that group did. You just append the captured text, which may be an empty string.

Maybe you are looking for

  • Out of memory error in IBM JVM

    Hi i am using websphere application server's dyna cache for getting performance optimiztion in my application. I am able to load values into the cache using the command cache api in the dyna cache.When i clear the cache for loading another set of val

  • IPhoto 09 MobileMe Gallery Sync

    Friends, I apologize if this has already been asked. I have searched and searched and searched and just cannot find an answer. Here's what I am trying to figure out. I have a decent sized photo library being managed by iPhoto 09. I have diligently or

  • Print Microsoft Word page range

    Is there a way for me to only print from page 11 to page 14 using the following script? $objWord = New-Object -comobject Word.Application $objDoc = $objWord.Documents.Open("c:\test.docx") $objDoc.PrintOut() $a = $objWord.Quit()

  • How do I call in to a support line?

    I have been waiting on and on and on to get a reply on how to reactivate my account with a new credit card.  This seems like an easy issue to resolve, one that doesn't require me waiting for a chat forum agent to respond, and then miss it if I leave

  • How can I run 2 differeny Firefox versions

    I have Win 7 x64 operating system. How can I run two different FireFox versions? I want to be able to run FF3.6 and FF10 But it seems its set up the way that I can only install one of them.