Regular Expression Challenge

Hello, everybody!
I'm trying to come up with a regular expression to validate a identifier that starts and ends with double quotes. That's what I have until now:
\"[a-zA-Z_][\w]*\"
This regex is working. It matches identifiers like:
"name"
"name_1"
"_name123"but the challenge that I couldn't solve is this: I would like to augment this regex to also accept escaped double quotes inside the string itself, like this:
"na""me"     (correct, double quote inside escaped by another double quote)
"name""""_1" (correct, two double quotes inside escaped by double quotes)
"""_name123" (correct, double quote inside escaped by another double quote)and reject strings that miss the escape double quote, like the following:
"na"me"
"name""" "_1"
"" "_name123"as you can see, besides the start and end quotes, if there's a double quote inside the identifier, it has to be followed +immediately+ by another double quote, it has to be a pair, no matter how many and where. I tried to find such a regular expression but I didn't have success. I couldn't find a way to say that a double quote inside the identifier has to be followed by another double quote.
Any help would be appreciated.
Thank you in advance.
Marcos

Marcos_AntonioPS wrote:
r035198x wrote:
Marcos_AntonioPS wrote:
..If you are not willing/able to learn about them and make an attempt then you will find it difficult to get help here.
You will also find it difficult to get help if you insult regulars when they try to advise you on following the posting guidelines by chosing an appropriate thread title.r035198x, I didn't insult regulars. But you insulted me. I consider saying that I was trying to make someone here do 'my homework' an insult. I think that the worst insults in life are the ones that we say in a sarcastic manner, like yours.
MarcosI can't think of one instance where a 'challenge' has been issued in these forums that was not an indirect request for someone's homework to be done. Yours could be the first but even then is stinks of "I can't be bothered to learn about look-ahead so can some kind person solve my problem for me?". Issuing a 'challenge' like this is an insult to us. It assumes we are gullible enough to do your work for you.
You can get somewhere towards a solution using look-ahead but you will have to place restrictions since regex can't count.

Similar Messages

  • Very challenging Regular Expression(for me atleast) ..HELP

    This is a complex situation for me and i would really appreciate if you could help me out with the regular expression that meets my condition
    Scenerio:
    Lets assume i am reading a file that has only numbers or integers in it. Now i need to read each line by line and print an error message if a condition is met.
    Consition is:
    If there is a number >= 50 in with  at least 5 zeros in front or 5 zeros back of it
    print"error encountered"
    Example 1
    12454540000000050584
    Print "error" because there are atlease 5 consecutive zeros in front of 50
    Example 2
    24546744500005800000000
    Print "Error" because there are atleast 5 consecutive zeros behind 80( which is greater than 50)
    Example 3
    24546744500005800000000068
    Print "error" message because there are atleast 5 consecutive zeros behing 58 BUT 68 does not meet the condition because there are only 4 consecutive zeros infront of it because rest of the zeros are already associated with 58 and cannot be recounted. Zeros are counted in a chunk of five and a chunk could only be counted once.
    Please resond to this thread if more clarification is needed.
    Appreciate your help. You guys ROCK.

    Hiklior wrote:
    This is a complex situation for me and i would really appreciate if you could help me out with the regular expression that meets my condition
    Scenerio:
    Lets assume i am reading a file that has only numbers or integers in it. Now i need to read each line by line and print an error message if a condition is met.
    Consition is:
    If there is a number >= 50 in with  at least 5 zeros in front or 5 zeros back of it
    print"error encountered"
    Example 1
    12454540000000050584
    Print "error" because there are atlease 5 consecutive zeros in front of 50
    Example 2
    24546744500005800000000
    Print "Error" because there are atleast 5 consecutive zeros behind 80( which is greater than 50)
    Example 3
    24546744500005800000000068
    Print "error" message because there are atleast 5 consecutive zeros behing 58 BUT 68 does not meet the condition because there are only 4 consecutive zeros infront of it because rest of the zeros are already associated with 58 and cannot be recounted. Zeros are counted in a chunk of five and a chunk could only be counted once.
    That last sentence makes me think that maybe regex is not the way to go here. Well that and what seem to math operations.
    I don't think I understand the more than 50 stuff.
    So here is I think what I do understand
    - more than 5 zeroes in front of a 5 is bad
    - I think once you have a pattern of zeros and then a 5 everything trailing the five is part of the zeroes until the END of the next set of zeros
    Is that right?

  • Regular Expressions for converting HTML to Structured Plain Text

    I'm writing a PL/SQL function that will convert HTML to plain text, but still preserve some of the formatting/line breaks. One of my challenges is in writing a regular expression to capture the text blocks while ignoring the markup. I'm trying to write an expression that will grab all of the text between start/end tags, but discard the tags. For example, to find all of the text between a start/end paragraph, I want to do something like:
    REGEXP_REPLACE('<p style="text-align:center&#59;">This is the body of the paragraph</p>', '<p.*>(.*)</p>', '\1||v_crlf' )
    where \1 returns the contents of the paragraph and v_crlf (declared earlier in the function) inserts a line break. I know there are more general expressions that will remove all tags, but I want to specifically identify the tags so I can process them appropriately. This way I can easily convert HTML to plain text for email and reporting without having to keep two versions around. Any help would be greatly appreciated. Once I get this worked out, I will repost with the function code for others to use. Thanks.
    Edited by: jritschel on Oct 26, 2010 9:58 AM

    Here's a function I wrote for an app. I'm not making in promises on it's accuracy as the app was just a proof of concept and never made it to production.
    function strip_html( p_clob in clob )
    return clob
    is
        l_out clob;
        l_test  number := 0;
        l_max_loops constant number := 20;
        i   pls_integer := 0;
    begin
        l_out := regexp_replace(p_clob,'<br>|<br />',chr(13)||chr(10),1,0,'imn');
        l_out := regexp_replace(l_out,'<p>',chr(13)||chr(10),1,0,'imn');
        l_out := replace(l_out,'<li>',chr(13)||chr(10)||'*<li>');
        l_out := regexp_replace(l_out,'<b>(.+?)</b>','*\1*',1,0,'imn');
        l_out := regexp_replace(l_out,'<u>(.+?)</u>','_\1_',1,0,'imn');
        loop
            l_test := regexp_instr(l_out,'<([A-Z][A-Z0-9]*)[^>]*>.*?</\1>',1,1,0,'imn');
            exit when l_test = 0 or i > l_max_loops;
            l_out := regexp_replace(l_out,'<([A-Z][A-Z0-9]*)[^>]*>(.*?)</\1>','\2',1,0,'imn');
            i := i + 1;
        end loop;
        return l_out;
    end strip_html;{code}
    The loop is there to handle nested HTML.
    Tyler Muth
    http://tylermuth.wordpress.com
    "Applied Oracle Security: Developing Secure Database and Middleware Environments": http://sn.im/aos.book
    Edited by: Tyler on Oct 26, 2010 10:03 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Logical AND in Java Regular Expressions

    I'm trying to implement logical AND using Java Regular Expressions.
    I couldn't figure out how to do it after reading Java docs and textbooks. I can do something like "abc.*def", which means that I'm looking for strings which have "abc", then anything, then "def", but it is not "pure" logical AND - I will not find "def.*abc" this way.
    Any ideas, how to do it ?
    Baken

    First off, looks like you're really talking about an "OR", not an "AND" - you want it to match abc.*def OR def.*abc right? If you tried to match abc.*def AND def.*abc nothing would ever match that, as no string can begin with both "abc" and "def", just like no numeric value can be both 2 and 5.
    Anyway, maybe regex isn't the right tool for this job. Can you not simply programmatically match it yourself using String methods? You want it to match if the string "starts with" abc and "ends with" def, or vice-versa. Just write some simple code.

  • Help in Regular expression

    Hello..
    I wanted to write a regular expression to match the foll string..
    <!--endclickprintexclude--><!--startclickprintexclude--> <!--endclickprintexclude-->
    <p> <b>NEW ORLEANS, Louisiana (CNN) </b>
    -- Two years after Hurricane Katrina devastated coastal areas of Louisiana and Mississippi, residents say much of America has forgotten their plight.
    </p> <!--startclickprintexclude-->
    I tried doing..
    Matcher matcher= Pattern.compile("<!--endclickprintexclude--> <p><b>([^<^>]+?)</p><!--startclickprintexclude-->", Pattern.CASE_INSENSITIVE).matcher(story);
    Its not working...
    is there any other soln?

    Theres probably a better way to do this but here's a way that works.
    import java.util.regex.*;
    public class RegexTester{
    public static void main(String[] args){
         String text =
         "<!--endclickprintexclude--><!--startclickprintexclude--> <!--endclickprintexclude-->" +
         "<p> <b>NEW ORLEANS, Louisiana (CNN) </b>" +
         "-- Two years after Hurricane Katrina devastated coastal areas of Louisiana and Mississippi," +
         "residents say much of America has forgotten their plight." +
         "</p> <!--startclickprintexclude-->";
         String regex = ">((?:\\s*[\\S&&[^<>]]+\\s*)*?)<";
         Pattern p = Pattern.compile(regex);
         Matcher m = p.matcher(text);
         while(m.find()){
         System.out.println("Match: '" + m.group(1) + "'");
    }

  • Help in regular expression matching

    I have three expressions like
    1) [(y2009)(y2011)]
    2) [(y2008M5)(y2011M3)] or [(y2009M5)(y2010M12)]
    3) [(y2009M1d20)(y2011M12d31)]
    i want regular expression pattern for the above three expressions
    I am using :
    REGEXP_LIKE(timedomainexpression, '???[:digit:]{4}*[:digit:]{1,2}???[:digit:]{4}*[:digit:]{1,2}??', 'i');
    but its giving results for all above expressions while i want different expression for each.
    i hav used * after [:digit:]{4}, when i am using ? or . then its giving no results. Please help in this situation ASAP.
    Thanks

    I dont get your question Can you post your desired output? and also give some sample data.
    Please consider the following when you post a question.
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Regular expression alphabets

    Hi
    I want to retrieve the data if the data contains a character or a space or '-' thru select query .
    Please help me in writing the combination of 3 with regular expression.
    Thanks!!

    VT wrote:
    Hi,
    Try this
    SELECT *
    FROM <TABLE> WHERE REGEXP_LIKE(<COLUMN>, '[a-z -][A-Z -]');cheers
    VTThat won't work as it's expecting at least two characters with the first having to be a-z (lower case) or space or "-" followed by A-Z (upper case) or space or "-".
    The correct way is either:
    [a-zA-Z -]or
    [[:alpha:] -]using the alpha set is often preferable as it can work differently with different character sets/languages rather than restricting to just the a-zA-Z ranges.
    Generating a reference for your own database characterset/language can be useful...
    SQL> select level-1 as asc_code, decode(chr(level-1), regexp_substr(chr(level-1), '[[:print:]]'), CHR(level-1)) as chr,
      2         decode(chr(level-1), regexp_substr(chr(level-1), '[[:graph:]]'), 1) is_graph,
      3         decode(chr(level-1), regexp_substr(chr(level-1), '[[:blank:]]'), 1) is_blank,
      4         decode(chr(level-1), regexp_substr(chr(level-1), '[[:alnum:]]'), 1) is_alnum,
      5         decode(chr(level-1), regexp_substr(chr(level-1), '[[:alpha:]]'), 1) is_alpha,
      6         decode(chr(level-1), regexp_substr(chr(level-1), '[[:digit:]]'), 1) is_digit,
      7         decode(chr(level-1), regexp_substr(chr(level-1), '[[:cntrl:]]'), 1) is_cntrl,
      8         decode(chr(level-1), regexp_substr(chr(level-1), '[[:lower:]]'), 1) is_lower,
      9         decode(chr(level-1), regexp_substr(chr(level-1), '[[:upper:]]'), 1) is_upper,
    10         decode(chr(level-1), regexp_substr(chr(level-1), '[[:print:]]'), 1) is_print,
    11         decode(chr(level-1), regexp_substr(chr(level-1), '[[:punct:]]'), 1) is_punct,
    12         decode(chr(level-1), regexp_substr(chr(level-1), '[[:space:]]'), 1) is_space,
    13         decode(chr(level-1), regexp_substr(chr(level-1), '[[:xdigit:]]'), 1) is_xdigit
    14    from dual
    15  connect by level <= 256
    16  /
      ASC_CODE C   IS_GRAPH   IS_BLANK   IS_ALNUM   IS_ALPHA   IS_DIGIT   IS_CNTRL   IS_LOWER   IS_UPPER   IS_PRINT   IS_PUNCT   IS_SPACE  IS_XDIGIT
             0                                                                   1
             1                                                                   1
             2                                                                   1
             3                                                                   1
             4                                                                   1
             5                                                                   1
             6                                                                   1
             7                                                                   1
             8                                                                   1
             9                                                                   1                                              1
            10                                                                   1                                              1
            11                                                                   1                                              1
            12                                                                   1                                              1
            13                                                                   1                                              1
            14                                                                   1
            15                                                                   1
            16                                                                   1
            17                                                                   1
            18                                                                   1
            19                                                                   1
            20                                                                   1
            21                                                                   1
            22                                                                   1
            23                                                                   1
            24                                                                   1
            25                                                                   1
            26                                                                   1
            27                                                                   1
            28                                                                   1
            29                                                                   1
            30                                                                   1
            31                                                                   1
            32                       1                                                                            1                     1
            33 !          1                                                                                       1          1
            34 "          1                                                                                       1          1
            35 #          1                                                                                       1          1
            36 $          1                                                                                       1          1
            37 %          1                                                                                       1          1
            38 &          1                                                                                       1          1
            39 '          1                                                                                       1          1
            40 (          1                                                                                       1          1
            41 )          1                                                                                       1          1
            42 *          1                                                                                       1          1
            43 +          1                                                                                       1          1
            44 ,          1                                                                                       1          1
            45 -          1                                                                                       1          1
            46 .          1                                                                                       1          1
            47 /          1                                                                                       1          1
            48 0          1                     1                     1                                           1                                1
            49 1          1                     1                     1                                           1                                1
            50 2          1                     1                     1                                           1                                1
            51 3          1                     1                     1                                           1                                1
            52 4          1                     1                     1                                           1                                1
            53 5          1                     1                     1                                           1                                1
            54 6          1                     1                     1                                           1                                1
            55 7          1                     1                     1                                           1                                1
            56 8          1                     1                     1                                           1                                1
            57 9          1                     1                     1                                           1                                1
            58 :          1                                                                                       1          1
            59 ;          1                                                                                       1          1
            60 <          1                                                                                       1          1
            61 =          1                                                                                       1          1
            62 >          1                                                                                       1          1
            63 ?          1                                                                                       1          1
            64 @          1                                                                                       1          1
            65 A          1                     1          1                                           1          1                                1
            66 B          1                     1          1                                           1          1                                1
            67 C          1                     1          1                                           1          1                                1
            68 D          1                     1          1                                           1          1                                1
            69 E          1                     1          1                                           1          1                                1
            70 F          1                     1          1                                           1          1                                1
            71 G          1                     1          1                                           1          1
            72 H          1                     1          1                                           1          1
            73 I          1                     1          1                                           1          1
            74 J          1                     1          1                                           1          1
            75 K          1                     1          1                                           1          1
            76 L          1                     1          1                                           1          1
            77 M          1                     1          1                                           1          1
            78 N          1                     1          1                                           1          1
            79 O          1                     1          1                                           1          1
            80 P          1                     1          1                                           1          1
            81 Q          1                     1          1                                           1          1
            82 R          1                     1          1                                           1          1
            83 S          1                     1          1                                           1          1
            84 T          1                     1          1                                           1          1
            85 U          1                     1          1                                           1          1
            86 V          1                     1          1                                           1          1
            87 W          1                     1          1                                           1          1
            88 X          1                     1          1                                           1          1
            89 Y          1                     1          1                                           1          1
            90 Z          1                     1          1                                           1          1
            91 [          1                                                                                       1          1
            92 \          1                                                                                       1          1
            93 ]          1                                                                                       1          1
            94 ^          1                                                                                       1          1
            95 _          1                                                                                       1          1
            96 `          1                                                                                       1          1
            97 a          1                     1          1                                1                     1                                1
            98 b          1                     1          1                                1                     1                                1
            99 c          1                     1          1                                1                     1                                1
           100 d          1                     1          1                                1                  1                           1
           101 e          1                     1          1                                1                  1                           1
           102 f          1                     1          1                                1                  1                           1
           103 g          1                     1          1                                1                  1
           104 h          1                     1          1                                1                  1
           105 i          1                     1          1                                1                  1
           106 j          1                     1          1                                1                  1
           107 k          1                     1          1                                1                  1
           108 l          1                     1          1                                1                  1
           109 m          1                     1          1                                1                  1
           110 n          1                     1          1                                1                  1
           111 o          1                     1          1                                1                  1
           112 p          1                     1          1                                1                  1
           113 q          1                     1          1                                1                  1
           114 r          1                     1          1                                1                  1
           115 s          1                     1          1                                1                  1
           116 t          1                     1          1                                1                  1
           117 u          1                     1          1                                1                  1
           118 v          1                     1          1                                1                  1
           119 w          1                     1          1                                1                  1
           120 x          1                     1          1                                1                  1
           121 y          1                     1          1                                1                  1
           122 z          1                     1          1                                1                  1
           123 {          1                                                                                    1     1
           124 |          1                                                                                    1     1
           125 }          1                                                                                    1     1
           126 ~          1                                                                                    1     1
           127                                                                   1
           128 Ç          1                                                                                    1     1
    etc.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

  • Help in query using regular expression

    HI,
    I need a help to get the below output using regular expression query. Please help me.
    SELECT REGEXP_SUBSTR ('PWRPKG(P/W+P/L+CC)', '[^+]+', 1, lvl) val, lvl
    FROM DUAL,(SELECT LEVEL lvl FROM DUAL
    CONNECT BY LEVEL <=(SELECT MAX ( LENGTH ('PWRPKG(P/W+P/L+CC)') - LENGTH (REPLACE ('PWRPKG(P/W+P/L+CC)','+',NULL))+ 1) FROM DUAL));
    I need the output as
    correct result:
    ==============
    val lvl
    P/W 1
    P/L 2
    CC 3
    But i tried the above it is not coming the above result. Please help me where i did a mistake.
    Thanks in advance

    Frank gave you a solution in your other thread. You could simplify it if you are on 11g:
    SQL> select * from table_x
      2  /
    TXT
    TECHPKG(INTELLI CC+FRT SONAR)
    PWRPKG(P/W+P/L+CC)
    select  txt,
            regexp_substr(
                          txt,
                          '(.*\()*([^+)]+)',
                          1,
                          column_value,
                          null,
                          2
                         ) element,
            column_value element_number
      from  table_x,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= regexp_count(txt,'\+') + 1
                       as sys.OdciNumberList
      order by rowid,
               column_value
    TXT                                      ELEMENT    ELEMENT_NUMBER
    TECHPKG(INTELLI CC+FRT SONAR)            INTELLI CC              1
    TECHPKG(INTELLI CC+FRT SONAR)            FRT SONAR               2
    PWRPKG(P/W+P/L+CC)                       P/W                     1
    PWRPKG(P/W+P/L+CC)                       P/L                     2
    PWRPKG(P/W+P/L+CC)                       CC                      3
    SQL>  SY.

  • Query help in regular expression

    Hi all,
    SELECT * FROM emp11
    WHERE INSTR(ENAME,'A',1,2) >0;
    Please let me know the equivalent query using regular expressions.
    i have tried this after going through oracle regular expressions documentation.
    SELECT * FROM emp11
    WHERE regexp_LIKE(ename,'A{2}')
    Any help in this regard would be highly appreciated .
       Thanks,
    P Prakash

    please go here
    Introduction to regular expressions ...
    Thanks,
    P Prakash

  • Urgent!!! Problem in regular expression for matching braces

    Hi,
    For the example below, can I write a regular expression to store getting key, value pairs.
    example: ((abc def) (ghi jkl) (a ((b c) (d e))) (mno pqr) (a ((abc def))))
    in the above example
    abc is key & def is value
    ghi is key & jkl is value
    a is key & ((b c) (d e)) is value
    and so on.
    can anybody pls help me in resolving this problem using regular expressions...
    Thanks in advance

    "((key1 value1) (key2 value2) (key3 ((key4 value4)
    (key5 value5))) (key6 value6) (key7 ((key8 value8)
    (key9 value9))))"
    I want to write a regular expression in java to parse
    the above string and store the result in hash table
    as below
    key1 value1
    key2 value2
    key3 ((key4 value4) (key5 value5))
    key4 value4
    key5 value5
    key6 value6
    key7 ((key8 value8) (key9 value9))
    key8 value8
    key9 value9
    please let me know, if it is not possible with
    regular expressions the effective way of solving itYes, it is possible with a recursive regular expression.
    Unfortunately Java does not provide a recursive regular expression construct.
    $_ = "((key1 value1) (key2 value2) (key3 ((key4 value4) (key5 value5))) (key6 value6) (key7 ((key8 value8) (key9 value9))))";
    my $paren;
       $paren = qr/
               [^()]+  # Not parens
             |
               (??{ $paren })  # Another balanced group (not interpolated yet)
        /x;
    my $r = qr/^(.*?)\((\w+?) (\w+?|(??{$paren}))\)\s*(.*?)$/;
    while ($_) {
         match()
    # operates on $_
    sub match {
         my @v;
         @v = m/$r/;
         if (defined $v[3]) {
              $_ = $v[2];
              while (/\(/) {
                   match();
              print "\"",$v[1],"\" \"",$v[2],"\"";
              $_ = $v[0].$v[3];
         else { $_ = ""; }
    C:\usr\schodtt\src\java\forum\n00b\regex>perl recurse.pl
    "key1" "value1"
    "key2" "value2"
    "key4" "value4"
    "key5" "value5"
    "key3" "((key4 value4) (key5 value5))"
    "key6" "value6"
    "key8" "value8"
    "key9" "value9"
    "key7" "((key8 value8) (key9 value9))"
    C:\usr\schodtt\src\java\forum\n00b\regex>

  • Bracket in Regular Expression constant?

    I am a bit puzzled by the behavior I am experiencing in LV 2011. I hope to get some light from experts out there.
    I am trying to parse a messy ASCII header file and after having split it into individual lines (strings), I use the "Match Regular Expression" function to remove some of the info before the substantial information.
    Some of the strings include square brackets ([, ]), which are special characters for the function, therefore, as documented in the help, one needs to precede them with a backslash.
    Example:
    I want to parse the following line:
       #PR [PR_DEV,I,2]
    One way (which I am using because of considerations related to the rest of the header) is the the following:
    Note that the first string constant is using "Code Display" whereas the second one is using "Normal Display".
    Why did I not put a backslash in front of the bracket in the first string, you may ask? Well, I did, but it disappeared after I typed the other characters. And reverting to "Normal Display" did not restore it.
    Of course, the first version does not parse the input string correctly, whereas the second one does it fine.
    In other words, the custom display string (which is convenient for cryptic codes such as \s* or to distinguish between space and tab...or simply ENTER tabs!) seems to mess up with the \[ combo (likewise with the \] one).
    It is not a huge deal. I can use the "Normal Display" mode, but I tend to think that this qualifies as a hidden "feature". And again, it is still a pain in the ... when dealing with special characters such as tabs, etc...
    Solved!
    Go to Solution.

    I think that [ is a special character which needs to be preceded by a backslash, but it is not one of the defined backslash characters (like \s). So, you need to put in two \\ to get one \ while in '\' Codes Display.
    You can put in any character by using \xx where the xx is a hex character using only upper case letters for A..F.  I converted the strings to byte arrays and tried to see what made the arrays match and the Match work.
    Lynn

  • Need help with regular expression

    I'm trying to use the java.util.regex package to extract URLs from html files.
    The URLs that I am interested in extracting from the HTML look like the following:
    <font color="#008000">http://forum.java.sun.com -
    So, the URL is always preceeded by:
    <font color="#008000">
    and then followed by a space character and then a hyphen character. I want to be able to put all these URLs in a Vector object. This doesn't seem like it should be too difficult but for some reason I can't get anywhere with it. Any help would be greatly appreciated. Thanks!

    hi gupta am not sure of the java syntax but i can tell u about the regular expression...try this....
    <font color="#008000">(http:\/\/[a-zA-Z0-9.]+) [-]
    i dont know the java methods to call...just the reg exp...
    Sanjay Acharya

  • Litte help with regular expression?

    Greetings all,
    I have a simple regular expression "(\\w+)\\s(\\w+)\\s(.+)"
    Which I want to match against the strings like "Acetobacter pasteurianus LMD22.1"
    But this always fails whenever there is a dot (.) character like "LMD22.1" in above string.
    How to solve this ?
    Thanks in advance.

    Shouldn't that be Acinetobacter?
    edit: nope, I'm wrong, you're right.
    Edited by: Encephalopathic on Apr 7, 2009 7:34 PM

  • Help regarding regular expression

    HI All ,
    Please see the following string
    String s = "IF ((NOT NUM4 IS ALPHABETIC ) AND NUM3 IS ALPHABETIC-UPPER AND (NUM5 IS GREATER OR EQUAL TO 3) AND (NUM5 IS NOT GREATER THAN 3) AND (NUM3 GREATER THAN 46) AND (NUM5 GREATER THAN NUM3) OR NUM3 LESS THAN 78) .";
    My problem is: i want to capture the part of this line which contains "ALPHABETIC ,ALPHABETIC-UPPER for ex :NOT NUM4 IS ALPHABETIC , NUM3 IS ALPHABETIC-UPPER.from that I have to capture the word num4 , num3 which are in these phrases only ;from the whole string whereever it exists along with the phrase,Can any one help me out by suggesting something.num4 and num3 are variable names

    I suspect you're right, Sabre, but I can't resist...
    import java.util.regex.*;
    * A rewriter does a global substitution in the strings passed to its
    * 'rewrite' method. It uses the pattern supplied to its constructor, and is
    * like 'String.replaceAll' except for the fact that its replacement strings
    * are generated by invoking a method you write, rather than from another
    * string. This class is supposed to be equivalent to Ruby's 'gsub' when given
    * a block. This is the nicest syntax I've managed to come up with in Java so
    * far. It's not too bad, and might actually be preferable if you want to do
    * the same rewriting to a number of strings in the same method or class. See
    * the example 'main' for a sample of how to use this class.
    * @author Elliott Hughes
    public abstract class Rewriter
      private Pattern pattern;
      private Matcher matcher;
       * Constructs a rewriter using the given regular expression; the syntax is
       * the same as for 'Pattern.compile'.
      public Rewriter(String regularExpression)
        this.pattern = Pattern.compile(regularExpression);
       * Returns the input subsequence captured by the given group during the
       * previous match operation.
      public String group(int i)
        return matcher.group(i);
       * Overridden to compute a replacement for each match. Use the method
       * 'group' to access the captured groups.
      public abstract String replacement();
       * Returns the result of rewriting 'original' by invoking the method
       * 'replacement' for each match of the regular expression supplied to the
       * constructor.
      public String rewrite(CharSequence original)
        this.matcher = pattern.matcher(original);
        StringBuffer result = new StringBuffer(original.length());
        while (matcher.find())
          matcher.appendReplacement(result, "");
          result.append(replacement());
        matcher.appendTail(result);
        return result.toString();
      public static void main(String[] args)
        String s = "IF ((NOT NUM4 IS ALPHABETIC ) " +
                    "AND NUM3 IS ALPHABETIC-UPPER " +
                    "AND (NUM5 IS GREATER  OR EQUAL TO 3) " +
                    "AND (NUM5 IS NOT GREATER THAN 3) " +
                    "AND (NUM3 GREATER THAN 46) " +
                    "AND NUM645 IS ALPHABETIC " +
                    "AND (NUM5 GREATER THAN NUM3) " +
                    "OR NUM3 LESS THAN 78 " +
                    "AND NUM34 IS ALPHABETIC-UPPER " +
                    "AND NUM92 IS ALPHABETIC-LOWER " +
                    "AND NUM0987 IS ALPHABETIC-LOWER) .";
        String result =
          new Rewriter("(NUM\\d+) +IS +(ALPHABETIC(?:-(?:UPPER|LOWER))?)")
            public String replacement()
              String type = group(2);
              if (type.endsWith("UPPER"))
                return "Character.isUpper(" + group(1) + ")";
              else if (type.endsWith("LOWER"))
                return "Character.isLower(" + group(1) + ")";
              else
                return "Character.isLetter(" + group(1) + ")";
          }.rewrite(s);
        System.out.println(result);
    }

  • Help on regular expression

    hi all
    i need to validate telephone number , and i tried to use the following expression :
    "[\\d][\\d][\\d]-[\\d][\\d][\\d][\\d]" or
    "[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" they did not seem to work. can anyone provide some help on this? thanks in advance.

    Hi,
    Can anyone provide me the regular expression for the following?
    1. String Should contain 7 letters (can include '*') followed by 5 alphanumeric characters i.e.5 numbers/letters
    For this one, I've written reg expn = ([a-zA-Z]*[*]*[a-zA-Z]*){7}\\w{5}
    But, somehow this is not working...can anyone pleaseeeee explain wots wrong with this one or give me alternate solution???????
    2. String should contain 7 numbers or 7 digits consisting of 1 letter & 6 numbers in varying order, no spaces.
    For this one, reg expn = (\\d{7})|((\\d*[a-zA-Z]\\d*){7})
    But this is also not working...... Please help!!!!!
    3. String should contain 9 numbers or 8 alphanumeric characters i.e. 8 numbers/letters or 13 numbers
    This one looks really simple, but still (\\d{9})|(\\w{8})|(\\d{13}) is not working.....Please helpppp
    I'll appreciate if any Regular Expresion expert can resolve my problem!!! Also, I'm using gnu-regexp-1.0.8.jar as we r not using JDK 1.4!!!! We've to use only this library, no other choice...so, please suggest!!!!!!

Maybe you are looking for

  • Is it possible to "export" the advance catalog research results ?

    Hello, I use Acrobat Pro 9 on windows xp. Is there any method to select & "export" all the results of an advance research to create (for example) a "porte documents" in one time, or to copy at once the documents in a different folder, or to print the

  • Event firing at item added and item updated in event receiver?

    Hi All, I have created event receiver on item added & item updated on document library. 1) On Item Added i am updating document library Title column with document Name and i have metadata for the file. 2) On Item Updated i am move that file with meta

  • Not able to connect RAC database from client

    Hi there Recently I have configured RAC in test environment. version 11.2.0.1. OS Redhat 5.9. Everything seems to be fine except not able to connect rac database from client.  Error is as under : C:\Documents and Settings\pbl>sqlplus test1/test1@myra

  • I saved my videos in finder, how do i move them into icloud?

    I saved my videos in finder in my video folder, how do i now move that folder into icloud?

  • Mark as Junk keyboard shortcut

    I would like an easier keyboard shortcut to mark a message as junk. I've tried using the keyboard shortcuts in system tools, but it's not working. I believe the menu item I am trying to assign to a short cut is "As Junk Mail". However, the key I assi