Problem with Regular Expression: XML comment parsing

I have create pattern to parse xml comments:
<!--(?!.*(<!--)).*-->It works fine but only problem that I have is that it parse only last occurrence :(

sabre150 wrote:
MrJbee wrote:
I have create pattern to parse xml comments:
<!--(?!.*(<!--)).*-->It works fineI'm surprised it works fine since the ".*" is greedy and will gobble as much as it can and you will end up matching from the start of the first comment to the end of the last comment.
but only problem that I have is that it parse only last occurrence :(Make the ".*" reluctant using ".*?" or, best of all, use an XML parser.
Edited by: sabre150 on Jan 11, 2010 4:00 PMFirst at thanks for reply.
Second it is not so greedy like it look. Because of that:
(?!.*(<!--))I can`t use xml parser since It is only part of my JEditor with styles. I use reg exp to highlight comments, strings, chars and so on....
By the way I try to replace .* => .*? and it is still no results. I mean only last is selected. Maybe you have an example on how to match structure if the do not
have specified substrings.
Something like this:
hello[^(guten tag)]*bye // I know that this is wrongEdited by: MrJbee on Jan 11, 2010 1:22 PM

Similar Messages

  • Problem with Regular Expression

    Hi There!!
    I have a problem with regular expression. I want to validate that one word and second word are same. For that I have written a regex
    Pattern p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
    Matcher m=p.matcher("nikhil nikhil");
    boolean t=m.matches();
    if (t)
              System.out.println("There is a match");
         else
              System.out.println("There is no match");
    The result I am getting is always "There is no match
    Your timely help will be much appreciated.
    Regards

    Ram wrote:
    ErasP wrote:
    You are missing a backward slash in the regex
    Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
    But this will fail in this case.
    Matcher m = p.matcher("Nikhil Nikhil");It is the reason for that *[a-z]*.The OP had [a-z][a-zA-Z]* in his code, so presumably he know what that means and wants that String not to match.

  • Problems with regular expressions.

    Hi all.
    I want to substitute within an xml file a string with the following structure:
    Referencer="//@Model/@OwnedElement.0/@OwnedElement.1/@OwnedElement.0/@OwnedElement.1/@OwnedElement.33 ..."
    where the dots mean that the string within the quotes may be repeated (separated by spaces) many times.
    I've tried to match such expression with java regex, with no luck. I thought running
    line.contains("Referencer=\"[^\"\\r\\n]*\"");
    would return true, but it didn't.
    Could anybody point me the right way?.
    Thank you all in advance.

    Method String.contains() does not take a regular expression - you need to use method String.matches() or class Pattern.
    This looks to be a good problem to solve using http://elliotth.blogspot.com/2004/07/java-implementation-of-rubys-gsub.html .

  • Problem with Regular Expressions

    Hi Everyone:
    I'm having a problem finding the easiest way to retrieve the replacement text that has been edited to insert back-references from previous matches. For instance,
    Lets say I want to use the below regular expression
    foo_bar([1-9])_fun
    on the search text
    foo_bar1_fun
    foo_bar2_fun
    foo_bar3_fun
    and then the replacement text would be
    foobar_fun$1
    so in the end I would get
    foobar_fun1
    foobar_fun2
    foobar_fun3
    What I would like to do is be able to extract the replacement text that has been modified with the back reference matches after I use the Matcher.appendReplacement(stringbuffer, string) method.
    So to clarify further, after I find the first match and use the appendReplacement Method, I would like to extract just the replacement that was made to the text, in this case foobar_fun1
    Thanks for any help!

    Alright, thanks for the reply. I'll try and make this a little more clear
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class LeClassName {
       public static void main(String[] args) {
          String input = "12341234foo_bar1_fun24342345foo_bar2_fun3522545foo_bar3_fun3423432";
          Pattern pattern = Pattern.compile("foo_bar([1-9])_fun");
          StringBuffer sb = new StringBuffer();
          Matcher matcher = pattern.matcher(input);
          while (matcher.find()) {
             matcher.appendReplacement(sb, "foobar_fun$1");
             //after the first pass through, I would like to extract, foobar_fun1
             // but what is in sb is 12341234foobar_fun1
          System.out.println(sb.toString());
    }I did find a solution myself after a bit of thinking but if anyone can come up with a better solution do tell and I'll award that person the answer. Thanks again!
    My Solution:
    private String fixBackReplacements() throws IndexOutOfBoundsException {
                String currentMatch = this.findMatch.group();
                Pattern temporaryPattern = Pattern.compile(findText);
                Matcher temporaryMatcher = temporaryPattern.matcher(currentMatch);
                return temporaryMatcher.replaceFirst(replaceText);
    }

  • Problem with  regular expression  validation

    hi,
       how can i validate folder structure
       conditions
         no two  forward slashes(/) in a sequence no  special characters
        " /w" and   "  '/'  "    
       e:/tomcat/ss/ss.text
           if(valStr.matches("((['/'])[a-zA-Z0-9_]*)")){
                    System.out.println("matches");   
             else
                    System.out.println("notmatches");
    this is no correct .
    please give me right solution       
    with regards
    ss

    hI,
      /appmg/dd/
    is  the paths for solaris( starts with /)
    i have to test  if it is valid path name or not
    with regards
    ss

  • Regular Expressions and comments

    Hello,
    I've got a problem with regular expressions. I Want to find special words like "todo" in java comments, but wasn't able to manage that satisfactory. I hope someone of you can give me an advice! :-)
    example of a comment:
    * comment text. todo: what is still todo.
    First of all, I tried this:
    /\*(.*?)todo(.*?)\*/
    but this version seems to ignore the borders of the comment and shows me also parts of the code.
    Then I tried this:
    /\*([^/]*?)todo(.*?)\*/
    this version returns good results, but doesn't notice html formatting like
    * <code> .... </code> text. todo: text
    So my idea now is to check whether a star precedes the slash, but I don't really know how to combine it.
    Or is there another simplier solution? Thanks for your hints!
    Greetz Jan

    Thanks for your answer, but when I take this expression the programm seems to hang-up. An operation that usually finishs in 3 secs didn't even in 10 minutes. :-( Do you have any idea what could be wrong?
    btw. can I take this one:
    pattern = Pattern.compile("/\\*(?:[^\\*]+|\\*(?!/))*todo.*?\\*/", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    matcher = pattern.matcher(text);
    text = matcher.replaceAll("");or do I have to take a this instead of replaceAll():
    while (matcher.find()) {
        text = text.substring(0, matcher.start(1)) + text.substring(matcher.end(1), text.length());
        matcher = pattern.matcher(text);
    }any hints?
    Greetz Jan

  • DOM Parser fails with regular expression using anchor (carat, dollar)

    I'm using version "Oracle XDK Java 9.0.4.0.0 Production"
    In trying to parse XML against schema: a regular expression fails to parse the data "8:00" with the following simple regular expression: "^.*$" (used to narrow the error)
    The error message is
    <Line 14, Column 25>: XSD-2025: (Error) Invalid text '8:00' in element: 'XYZ'
    If I remove the anchors and just have ".*", the data is parsed successfully.
    I dont understand why the parse fails when I use a anchors in the regular expression, and the java Pattern/Matcher classes succeed with the anchors?

    That "ns670" string is an xml namespace prefix. it should have a corresponding xml namespace declaration somewhere in the xml document (i'm guessing you have not shown the whole document). the actual value of an xml namespace prefix is meaningless. if you parse the xml with a namespace aware DOM parser, it should generate Nodes with the correct namespace. the namespace is the value you care about when extracting data from the document, not the namespace prefix.
    alternately, if you parse the document using a namespace aware DOM parser, you can just look for nodes based on their "local" name (the part after the ":" separator) and ignore the namespace/prefix.
    whatever you do, please do not parse the xml with a regex, see this http://stackoverflow.com/a/1732454/552759 for details (applies to xml as well).

  • 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>

  • Problems with reports and XML-publisher - No XML

    Hi!
    I'm having a problem with Apps and XML-publisher. I made a report file, which queries some views. When executing in reports, I get all the data I expect.
    Now, when I upload the reportfile to Apps and let it generate XML, my xml-file is empty (well, almost empty)
    <?xml version="1.0" ?>
    <!-- Generated by Oracle Reports version 6.0.8.27.0 -->
    <T03501684>
    <LIST_G_PERSOON>
    <LIST_G_PERSOON />
    </T03501684>
    Anyone who can shed any light upon this problem?

    OK, finally solved the problem... A good night's sleep always helps ;).
    After just trying each queried table one after an other, I found the problem:
    The difference between Oracle Apps (Dutch locale) and the reports builder (English) is the language... And our functional people have changed some names, but the Dutch ones, leaving the english names in place and one of the tables I query has language specific data, which is also appears in a where clause.

  • Problems with regular Texting since iOS 7.0.3

    Hello, I have an iPhone 5s recently upgraded to iOS 7.0.3 via OTA update. I never use iMessage, I have an unlimited text plan, so I always have used SMS with everyone. However, after this last update, I have problems with regular SMS. I can send SMS to everyone as usual, but can only get text messages from some-all of them using iPhone 5 with at least the lastest iOS6 version. I have noticed then only way to text them now is to turn on iMessage, otherwise I keep missing their replies. These are people, that until the last upgrade, I was texting with on a regular basis with no problems using plain SMS with iMessage option OFF. Contrary to most, I don't want to use iMessage but rather use regular carrier provided SMS.
    For instance, both my son and daughter use an iPhone 5 with iOS 7 (but not the latest patch 7.0.3) installed, I can text with my son OK, but can't get any texts from my daughter, can only communicate with her using iMessage-BTW, we are all on the same network on a family plan. Can't understand this at all. Since I can SMS with some, but not others I don't think this is a problem with my carrier but rather a problem with my phone since the update to 7.0.3, and they say I am the only one they have problem with texting with and I am the only one on the new software version.
    Anyone else has noticed this issue.

    I wonder if this may have something to do with iMessage on my Macs. Recently updated to Maverirks and the iMessage app on my Macs was set up to my email and mobile phone (it wasn't before). I wonder if this is so, then whoever I send an SMS to that has iMessage on and replies back, will be picked up by iMessage since is turned on on my Mac, since replies go to the Mac but not my phone. If the sender has iMessage off, I get the SMS fine.

  • Grouping & Back-references with regular expressions on Replace Text window

    I really appreciate the inclusion of the Regular Expressions in the search & replace feature. One thing I am missing is back-references in the replacement expression. For instance, in the unix tools vi or sed, I might do something like this:
    s/\(firstPart\) \(secondPart\) \(oldThirdPart\)/\2 \1 newThirdPart/g
    which would allow me to switch the places of firstPart and secondPart, and totally replace thirdPart. If grouping and back-references are already present in the Replace Text window, how does one correctly invoke them?

    duplicate of Grouping & Back-references with regular expressions on Replace Text window

  • Probleme with PCI Express Root Complex

    I bought an hp 15t - j100 with Windows 8.1 but on windows 8.1 but i needed change to windows 8 and now i have a problem with PCI Express Root Complex code 28. The drives i have donwload for hp site http://h10025.www1.hp.com/ewfrf/wc/softwareCategor​y?os=4158&lc=en&cc=us&dlc=en&sw_lang=&product=6521​...
    I need help to solve that problem
    thanks
    and i waiting for help
    This question was solved.
    View Solution.

    Hi:
    You need this driver...
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloa​dIndex?softwareitem=ob-124661-1&cc=us&dlc=en&lc=en​...

  • Assistance with Regular Expression and Tcl

    Assistance with Regular Expression and Tcl
    Hello Everyone,
      I recently began learning Tcl to develop scripts for automating network switch deployments. 
    In my script, I want to name the device with a location and the last three octets of the base mac address.
    I can get the Base MAC address by : 
    show version | include Base
     Base ethernet MAC Address       : 00:00:00:DB:CE:00
    And I can get the last three octets of the MAC address using the following regular expression. 
    ([0-9a-f]{2}[:-]){2}([0-9a-f]{2}$)
    But I have not been able to figure out how to call the regular expression in the tcl script.
    I have checked several resources but have not been able to figure it out.  Suggestions?
    Ultimately, I want to set the last three octets to a variable (something like below) and then call the variable when I name the switch.
    set mac [exec "sh version | i Base"] (include the regular expression)
    ios_config "hostname location$mac"
    Thanks for any assistance in advance.
    Chris

    This worked for me.
    Switch_1(tcl)#set result [exec show ver | inc Base]   
    Base ethernet MAC Address       : 00:1B:D4:F8:B1:80
    Switch_1(tcl)#regexp {([0-9A-F:]{8}\r)} $result -> mac
    1
    Switch_1(tcl)#puts $mac                               
    F8:B1:80
    Switch_1(tcl)#ios_config "hostname location$mac"      
    %Warning! Hostname should contain at least one alphabet or '-' or '_' character
    locationF8:B1:80(tcl)#

  • How to search with regular expression

    I make pdx files so that I can search text quickly. But Acrobat doesn't provide a way to search with regular expression. I'm wondering if there is a way that I don't know to search for regular expression in Acrobat Pro 9?

    First, Acrobat must "mount" the PDX.
    As "Find" does not use the cataloged index, use Shift+Ctrl+F to open the advanced search dialog.
    It may be helpful to first enter Acrobat Preferences and for the Search category tick "Always use advanced search options".
    Back to the Search dialog - use the drop down menu for "Look In" to pick "Select Index" then, if no PDXs show, click the Add button.
    In the Open Index File dialog, browse to the location of the desired PDX and select it.
    OK out and use "Return results containing" to pick a "Match ..." requirement or Boolean.
    To become familiar with query syntax, for Acrobat, it is good to review Acrobat Help.
    http://help.adobe.com/en_US/Acrobat/9.0/Professional/WS58a04a822e3e50102bd615109794195ff-7 c4b.w.html
    Be well...

  • Get the string between li tags, with regular expression

    I have a unordered list, and I want to store all the strings between the li tags (<li>.?</li>)in an array:
    <ul>
    <li>This is String One</li>
    <li>This is String Two</li>
    <li>This is String Three</li>
    </ul>
    This is what have so far:
    <li>(.*?)</li>
    but it is not correct, I only want the string without the li tags.
    Thanks.

    No one?
    Anoyone here experienced with Regular Expression?

Maybe you are looking for

  • ICloud and Multiple Apple ID Mess

    Hi, I seem to have made a mess of my iCloud and AppleID accounts.  Here's the timeline: Years ago when I got my first iphone (3G), and being a canadian customer, 1) I signed up for a US appleID with primary emailA so I can access the US iTunes store

  • Beeps when connecting iPod to A/V adapter

    Hello, I have a PXP01 from Peripheral Electronics. Whenever I plug my iPod into the dock connector, my iPod beeps twice. Is his normal. I have never used a dock before. Thanks.

  • Comm Channel content conversion

    Hi everyone, I have an existing interface IDOC to File scenario, in which I want to drop one field from the final output file. But I can't remove that field from the interface as it is is required for business logic till the very end. Can I acheive t

  • Does anybody know of a good microphone?

    I have had a microphone for quite some time, but I want to upgrade. I play the saxophone, but a microphone that records well "all over" is what I'm looking for. Any suggestions ?

  • How to Install SQL 2005 with command MS SQL 2005.

    Hello All, Where can I get the guide for  installaling ECC 6.0+MS SQL 2005/2008 from command prompt. I checked the standard work guides at market place but no hint found for command line installation. Please help me. Thanks, Anu