Trouble with tribbles, i mean regular expressions

Hi all
im trying to make a regular expression that finds all the comments in a given string
stuff like this
/* this is my comment */
then what i want to do is to remove all those found comments from the string and leave me with the original string without any comments.
anyway i know i need a pattern but i cant get my pattern right, this is what i have at the moment
Pattern remComment = Pattern.compile(" ^\\*?[\\w\\s\\W]+?*\\ ", Pattern.DOTALL | Pattern.MULTILINE);
can anyone help me and let me know where im going wrong
im basically trying to say any thing that starts with \* <any other text here> until a *\
thanks

There is something else wrong, I just tryied:
* Comments.java
* version 1.0
* 07/06/2005
package samples;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
* @author notivago
public class Comments {
     * @param args
    public static void main(String[] args) {
        String comment =
            "/*\r\n" +
            "does this do it won\r\n" +
            "*/\r\n" +
            ".activegrouptab\r\n" +
            "{\r\n" +
            "white-space:nowrap;\r\n" +
            "border-top-width:1pt;\r\n" +
            "cursor:hand;\r\n" +
            "}\r\n" +
            "/*\r\n" +
            "does this do it too\r\n" +
            "*/\r\n" +
            ".activegrouptabdisabled\r\n" +
            "{\r\n" +
            "font-family:verdana;\r\n" +
            "font-size:7pt;\r\n" +
            "}\r\n" +
            "/*\r\n" +
            "does this do it free\r\n" +
            "*/\r\n" +
            ".activesectiontab\r\n" +
            "{\r\n" +
            "width:90%;\r\n" +
            "background-image:url(hocbt.gif);\r\n" +
            "overflow:auto;\r\n" +
            "color:#ffffff;\r\n" +
        Pattern remComment = Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher matcher = remComment.matcher(comment);
        while( matcher.find() ) {            
            System.out.println( "The comment: \n" + matcher.group() );
            System.out.println("----");
}with the output:
The comment:
does this do it won
The comment:
does this do it too
The comment:
does this do it free
----

Similar Messages

  • PrintWriter issue with Directory Traversal and Regular Expression

    This is a follow up to my previous question on the forum. I am developing a program traverses the hard drive for information. If it finds the said information in any of the file (based on the regular expression wriiten) it must print the output into the file. Currently I am able to traverse the harddrive perfectly, the regular expression and the search is perfect and when I print the output into the local console, I am able to derive perfect results. But when I use the PrintWriter to write the output into the flight, it writes NOTHING into the file. I have been scouring all over the Internet for an answer, but havent been able to find. Would highly appreciate if someone can tell me what I am doing wrong and provide some guidance on how to get it right.
    public class myClass{
        BufferedReader br;
        String pcv;
        Pattern scPattern = Pattern.compile("Some regular expression");
        Matcher match = null;
        Pattern newPattern = Pattern.compile("Some regular expression");
        Matcher newMatch = null;
        String mvCheckVal;
        Matcher mvMatch;
        PrintWriter pw;
        void recursiveMethod(File dir) throws Exception {
                pw = new PrintWriter(new FileWriter("outputFile.txt"));
                pw.println("Opening pw stream.....");
                File[] files = dir.listFiles();
                String[] fileList = dir.list();
                for (int i = 0;i < files.length; i++) {
                    if (files.isDirectory()) {
    continue;
    } else if (files[i].isFile()) {
    br = new BufferedReader(new FileReader(files[i]));
    pw.println("BR is opening....");
    String line;
    while((line = br.readLine()) != null) {
    match = scPattern.matcher(line);
    if (match.find()) {
    pcv = line.substring(match.start(), match.end());
    System.out.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv)); //This is working perfectly
    pw.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv)); //This does not print anything at all
    System.out.println("Files: " + files[i]);
    System.out.println("");
    pw.println(" Files: " + files[i]);
    pw.println("");
    System.out.println("Closing I/O....");
    br.close();
    pw.close();
    public static void main(String[]args) throws Exception {
    File dir = new File("C:/");
    myNewClass acf = new myNewClass();
    acf.myClass(dir);

    @ejp
    I am afraid that it is not working. Can you please tell me what I doing wrong.
    void myMethod(File dir) throws Exception {
                bw = new BufferedWriter(new FileWriter("outputFile.txt"));
                File[] files = dir.listFiles();
                String[] fileList = dir.list();
                for (int i = 0;i < files.length; i++) {
                    if (files.isDirectory()) {
    myMethod(files[i]);
    } else if (files[i].isFile()) {
    br = new BufferedReader(new FileReader(files[i]));
    String line;
    while((line = br.readLine()) != null) {
    match = scPattern.matcher(line);
    if (match.find()) {
    pcv = line.substring(match.start(), match.end());
    System.out.println("Match: " + pcv + " Context: " + match.replaceFirst(pcv));
    bw.write("Match: " + pcv + " Context: " + match.replaceFirst(pcv));
    br.close();
    bw.write("Files: " + files[i]);
    bw.write("");
    bw.close();
    public static void main(String[]args) throws Exception {
    File dir = new File("C:/");
    myClass acf = new myClass();
    acf.myMethod(dir);

  • Troubles with Tribbles! ... er I mean Trouble with JMF

    Recently downloaded JMF and updated my classpath for both
    JMFHOME=C:\JMF2.1.1
    CLASSPATH=%JMFHOME%\lib\jmf.jar;.;%CLASSPATH%But, my Eclipse IDE does not want to recognise the javax.media library... any ideas?

    Huh... didn't know that. Is that because it doesn't require the JDK to run apps through Eclipse? Why does Eclipse ignore the system classpath?When Eclipse is launched, it defines its own classpath, which does not include a user's system classpath. Equivalent behavior is seen with the use of the -classpath flag with java and javac, where defining a classpath at startup disables the automatic inclusion of the system classpath. This helps reduce library conflicts.
    How might I go about doing so? This is a new concept for me.[Eclipse docs - Java Build Path Page|http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-123.htm]
    You may also be interested in [How Classes are Found|http://java.sun.com/javase/6/docs/technotes/tools/findingclasses.html] and the [Javapedia: Classpath|http://wiki.java.net/bin/view/Javapedia/ClassPath].
    ~

  • Trouble with iTune and multiple airport express

    Hi,
    I have a wifi network at home, a PC with windows XP and iTunes, and two airport express stations in other rooms.
    I can't figure out why iTunes sometimes sees the "other speakers" (ie airport express stations), sometimes don't, and sometimes sees only one of the two.
    The leds are always green on the remote stations, and they are seen in the airport administrator.
    Closing iTunes and running it again usually helps (but not always)
    Is that something anyone already experienced ?
    Thx for help.
    Nico

    It has been working fine for two days nows, and this morning : no express stations on iTunes...
    And they are neither seen in the Aiport Admin utility .
    Message was edited by: NicoV

  • I'm having trouble with internet radio thru Airport Express with itunes 7.

    The new itunes 7 is working okay for me except for one thing. For some reason I have a buffering problem between my computer and my Airport Express when I feed internet radio to it. Playing it through my computer speakers works just fine. Normal itunes music files seem to be okay either way. This started happening when I installed itunes 7. I have reset the base station and it hasn't improved things. Is it just coincidence? Anyone got any clues?
    Powerbook 15"   Mac OS X (10.3.9)  

    Same problem here. Some streams are playing correctly and others play in a strange manner, like a mix.
    I also got this problem with iTunes 7. I hope that Apple will fix it in a future update so that I can listen to every station over my Airport Express.

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

  • Item Validation using Regular Expression

    Hi,
    I am trying to apply a Validation to a text field item, with the type as Regular Expression.
    The text input into the field should be in a HH:MM:SS format, ie 05:30:00 (for 5:30am).
    The text I am placing in the 'Validation Expression 2' box is:
    [0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]
    This doesn't seem to work and I get an error message when I enter text in the correct format.
    I have even tried to use other comparisons, for example:
    or
    .{8}
    but these still give me an error message.
    Anyone have any ideas?

    Thanks for your help Flavio, the Regular Expression tool is really helpful.
    When I use this tool to compare strings with my regular expression, I get output = TRUE, which means I'm getting it right, but for some reason when I copy the same Regular Expression syntax into APEX, it doesn't work.
    I try to input correct strings into the field that is validated by the Reg Expr, but it still gives me an error.
    It seems to be something I am doing wrong within the application, but I can't figure out what I'm missing.
    I am creating an Item Level Validation with details:
    Type: Regular Expression
    Validation Expression 1: P23_BUS_DAY_COVERAGE_START
    Validation Expression 2: ^(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$
    Has anyone had similar problems using regualr expression validation in APEX?

  • How do I have to define a regular expression to filter out data from file?

    Hi all,
    I need to extract parts of lines of a ASCII file and didn't get it done with my low knowledge of regular expressions
    The file contains hundreds of lines and I am just interested in a few lines, within that lines I just need a part of the data.
    One original line looks like that:
    TP3| |TP_SMD|Nicht in Stueckliste|~TP TP_SMD TESTPUNKT|-|0|87.770|157.950|0|top|c| |other|TP_SMD|TP_SMD_60RF-TP
    Only the bold and underlined information is of interest, I don't need the rest.
    I can open that file, read in each line but then I am struggling to pick out only the lines of interest (starting with TP), taking that TP with its number and the coordinates following later on and then writing these shortened lines to a new text file. So the new line should look like that:
    TP3; 87.770;157.950;0 (It doesn't matter if the separator will be ; or |)
    I thought of using regular expressions - is that the right way or is there a better approach?
    Thanks & regards,
    gedi, using LabVIEW 8.5
    Regards,
    gedi

    Hi max,
    for finding a specific part of a string you can use the "Match Pattern" VI, it is located in the Strings Palette.
    Maybe the Extract Numbers.vi example in the examples browser library can help you.
    What I did to filter out my data of interest is first to sort out only the columns which I want to have -
    then there are still a lot of lines remaining I don't need (this is the thing described above).
    The rest I am going to filter out with a (then easy) regular expression with the "Match Pattern" VI.
    Regards,
    gedi
    Regards,
    gedi

  • Validate cfinput using regular expression

    Hi,
    can somebody help me valditing an cfinput field using regular expressions?
    First digit must be a number or "R".
    Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.
    I try this, but it doesn't work (Sorry I'm a beginner using regex).
    <cfinput type="text" name="field1" required="yes" validate="regular_expression"  pattern="[0-9Rr][0-9a-zA-Z]*"  maxlength="15">
    Thank you in advice!
    Claudia

    You haven't told your regex to match the entire string, so it will "pass"
    any string that has your match anywhere within it, so like as long as it's
    got an R or a digit in it: it's OK.
    To tell it to match the entire string, anchor it to the start and end of the
    string with ^ and $ respectively.
    Regular expression syntax: Using special characters
    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38f -7ffb.html#WSc3ff6d0ea77859461172e0811cbec0a38f-7fef
    Adam

  • Regular expression vs oracle text performance

    Does anyone have experience with comparig performance of regular expression vs oracle text?
    We need to implement a text search on a large volume table, 100K-500K rows.
    The select stmt will select from a VL, a view joining 2 tables, B and _TL.
    We need to search 2 text columns from this _VL view.
    Using regex seems less complex, but the deciding factor is of course performace.
    Would oracle text search perform better than regular expression in general?
    Thanks,
    Margaret

    Hi Dominc,
    Thanks, we'll try both...
    Would you be able to validate our code to create the multi-table index:
    CREATE OR REPLACE PACKAGE requirements_util AS
    PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2);
    END requirements_util;
    CREATE OR REPLACE PACKAGE BODY requirements_util AS
    PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2)
    AS
    tl_req pjt_requirements_tl%ROWTYPE;
    b_req pjt_requirements_b%ROWTYPE;
    CURSOR cur_req_name (i_rqmt_id IN pjt_requirements_tl.rqmt_id%TYPE) IS
    SELECT rqmt_name FROM pjt_requirements_tl
    WHERE rqmt_id = i_rqmt_id;
    PROCEDURE add_piece(i_add_str IN VARCHAR2) IS
    lx_too_big EXCEPTION;
    PRAGMA EXCEPTION_INIT(lx_too_big, -6502);
    BEGIN
    io_text := io_text||' '||i_add_str;
    EXCEPTION WHEN lx_too_big THEN NULL; -- silently don't add the string.
    END add_piece;
    BEGIN
         BEGIN
              SELECT * INTO b_req FROM pjt_requirements_b WHERE ROWID = i_rowid;
              EXCEPTION
              WHEN NO DATA_FOUND THEN
              RETURN;
         END;
         add_piece(b_req.req_code);
         FOR tl_req IN cur_req_name(b_req.rqmt_id) LOOP
         add_piece(tl_req.rqmt_name);
    END concat_columns;
    END requirements_util;
    EXEC ctx_ddl.drop_section_group('rqmt_sectioner');
    EXEC ctx_ddl.drop_preference('rqmt_user_ds');
    BEGIN
    ctx_ddl.create_preference('rqmt_user_ds', 'USER_DATASTORE');
    ctx_ddl.set_attribute('rqmt_user_ds', 'procedure', sys_context('userenv','current_schema')||'.'||'requirements_util.concat_columns');
    ctx_ddl.set_attribute('rqmt_user_ds', 'output_type', 'VARCHAR2');
    END;
    CREATE INDEX rqmt_cidx ON pjt_requirements_b(req_code)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('DATASTORE rqmt_user_ds
    SYNC (ON COMMIT)');

  • Troubles with regular expressions

    I seem to be having problems writing my regular expression. I check it on a regex testing website and it should work. Maybe I am doing something wrong because it is in Java and not Perl? I was wondering if someone could give me a little help?
    Pattern p = Pattern.compile("<.*posttitle.*h2>", Pattern.DOTALL);
            Matcher m = p.matcher(content);
            boolean b = m.matches();That's what my regular expression looks like but the boolean b keeps returning false. The text I am looking at is the source code of [dailypoetryclub.com|http://dailypoetryclub.com] and I want to basically pull out just the links of each day's topic. Any ideas what I'm doing wrong?

    1) Sounds like you need find() not matches() (matches look for the whole string to match exactly) if you are looking for the pattern in a long string.
    2) You should make the ".*" reluctant or it will take more than you expect.

  • The trouble with 'expression' -- how to edit that

    I just walked to the corner bodega ( even though its korean sooo bodega is misleading ).. to get some beer...
    ITS BEER THIRTY -- yipee !
    and on way back down the block where I live ( which is suburban ) some boy kid on a bike was riding and playing with a girl kid ( probably was his slightly older sister - these kids probably around 12 years old ) in front of a rental property with some spanish americans hanging out in their cemented yard on hammocks near bar b q...with their own kids...(they have planted another hopeful "veg garden" around the perimeter of their so called yard...tomato plants etc )...so anyway, the picture here is a "neighborhood" of sorts with a somewhat lower middle class family atmosphere in a fairly lower class area on the verge of becoming middle class ( with God's help ).
    And anyway, I passed by the boy kid on the bike and smiled at him cause he seemed to be a decent kid having fun with his friend ( they were sorta laughing about something and having fun before I showed up as the big "adult" and looked at me ). His smile back was like sunshine and true and he immediately recognized he could keep having fun with his friend and I wasn't a "threat" , but instead some sorta "neighbor".  She did the same more or less ( I think she had some devious design re: the game they were playing ... like " OK, you think you're so great on that bike, try to CHASE me ! " or something like that....kid stuff... and fun thank God.  This neighborhood has it's share of bad things going on in the streets at times.  And that leads to my focus on " The trouble with expression".
    A lot of people, like me for example, can't express themselves well in some ways. I didn't say , " Hi there kids !  What's new ? " when I met them on the way back from the bodega.  I didn't stop and ask what the heck they were laughing about.  Nor did I speak to the spanish people adjacent to the kids ...in their "yard" ...with the bar b q and hammock and obvious friday afternoon socializing they were into....
    We in nyc area are typically a mixed bag of races... I'm white, kids were african amer ( black but more like brownish if you ask me ), spanish people like mexicans IMO... who cares.  This is suburbia so you can imagine how more mixed it is in the city.
    Anyway, the reason I don't express myself so well in situations like that ( spontaneously on the street ) is cause I used to stutter real bad as a kid.. couldnt talk... so I clamed up. All my life I've been fighting that disability ( and other "challenges" re: learning, reading , writing, asthma , etc ) in terms of the "repercusions".  Kids like me make fun of me cause I stutter...I can't fight back verbally and lash out physically... become a "maniac".  Get kicked out of city schools etc...  Trouble maker.  Can't express myself, fight back with words....when kids are mean to me. After a while they dont matter much as if they are mean I just keep quiet and keep mouth shut and start "thinking" instead... how to keep on top of this person and not let things get crazy... meet the challenge.
    Turns out I'm not stupid and at some point my being " quiet" becomes a positive thing.. peers start asking my advice.. I'm suddenly a " deep thinker" in their eyes.  I go from being disabled ( stupid ) to being " a deep thinker" about the age of puberty... when nobody knows what they are doing anymore.
    I start thinking about expressing myself some other way than talking.. like maybe draw pictures... paint stuff, do things to have fun with people that doesnt put me in the " limelight".. where I have to talk etc.  More success follows this tendency to socialize and express myself... and I discover that chics like the strong silent type.
    ( I have been into gymnastics thru my fathers infactuation with it since age 2 -- which I think eventually ( inadvertantly ) " cured me " of many of my learning disabilities etc --  (talk to an OT about this and modern child development stuff to know what I mean here )
    Meanwhile I am very fond of dogs as my family has dogs one after the other and I am one of their best friends. I find I can communicate with dogs better than I can communicate with people sometimes.  This seems to be a problem in some cases with some people, but for me it never got crazy... where I " loved dogs " more than I " love people ".  I have never loved any dog more than any person and shudder when I think of those who do.  Those people who do have more problems than I ever had to deal with.
    And now, after all these years ( I am now 60 ), working on movies and tv stuff etc as a crew person with some college fine art schooling ( eventual photo major ) to get me started, I got into this " editing " stuff... A program I can actually " use " on my mousey computer introduces me to a more " final product " than I ever had access to before.
    BUT I don't shoot motion pic stuff, cant afford that - and never could before basically, and now I think about the triple threats and future of movies and tv as a business... as well as the tools ( in this case the editing programs in conjunction with the cameras ( arri, panavision etc ) ) and the desire to express something ...
    This has to be ( if you want an audience ) ... " tell a story ".  You could just put a camera on a rocket ( strap it to the rocket ) and shoot the takeoff etc and show that.. but you need a V.O. saying " well, I just shot off a rocket and this is what it looked like"...to bring the experience to the audience... or else IMO there is no story.
    Which leads to what's going on now in the world of reality tv, episodic tv , some big movies, etc.  Telling a story is more than showing you stuff that you just wouldnt have seen if you hadn't been there yourself. Telling a story is more like saying something that bridges the gap between your own experience of life and its challenges ( of being part of your neighborhood and making sense of your own childhood and being an adult now maybe ).. and what others also have gone through to get to the same conclusions....
    This is the object of " expression" IMO, whether you can talk about it, draw pictures about it, or make music about it...
    And the editing program is a tool to help do that.. it is not the end all or purpose of life or the " personal crusade" in the long run.
    It's one reason scary snakes often shock people out of their desire for comfort and predictable living... makes you think about that one serpent in the garden of eden you create for yourself .... and IMO who cares what editing program you use to write that and shoot it ??

    Steve Grisetti, the MOD of the Premiere Elements forum and co-founder of a video/photo/editing Web site, Muvipix, did a nice article, "Don't just make a movie - tell a story." His audience was more consumer video editors, than the folk that we see around here, but his points were well-made, and were embraced by many in the Muvipix community.
    I think that too many, forget that concept - and I am talking Hollywood and NYC here. It's almost as if, when the story breaks down, they instinctively know to throw in a car chase, or big explosion.
    I know that I cite it too often around The Lounge, but that was what I enjoyed most about the LOR trilogy. It told a story. Now, though I had some exposure to the story, when much younger, I have to admit that I never read Tolkien, though almost everyone, that I knew, was busy with every book. Still, I only knew some of the high points, and not much more. However, almost immediately, I was drawn into the story, and only wished that I did not have to wait so long between episodes. The FX were cool, and I am a technoid sort, but it was the story that hooked me. I had read several articles on the FX production, so WAS looking for some of that, but what I wanted was the story. This is one that I will buy the BD "Director's Cut" of, and do a marathon. I have seen each segment, maybe three times, but never back to back to back. I still need to fill in a few blanks, and an entire day of viewing should do that - no phone, no visitors, nothing but LOR.
    As far as human communications, I can talk, even more than I write here, but only concerning things that I care about. I am horrible at "small talk," and would rather addrss an auditorium of 10,000, on something that matters to me, than talk about the weather to a single person at a fund raiser. Not that long ago, I was seated next to a potential donor at a charity dinner. I was rather dreading it, and when she mentioned that she did not drink (what, no wine?), I was worried. At some point, early in the evening, the subject turned to politics. Now, I usually am very quiet on my feelings, as they are not exaclty politically correct, and worry about hurting feelings, or making a scene. I fielded a question on Senatorial candidates, and just decided to answer from my heart. Her eyes lit up, and I did not notice that the event had ended. Her husband was standing, as was my wife, and we were talking politics, talk-radio, FoxNews, Senator John Kyl, Will Rogers and much more. I found that we were kindred spirits. Finally, our spouses pulled us apart, and we departed. We continued that conversation at 2 - 3 more events during "the season." One day, my wife informed me that she had just given $10M to the foundation - the largest single gift ever. At least she wasn't a screaming liberal, as I would surely have really messed up the deal... However, had it all been small talk, I would have found a reason to excuse myself and hide in the bar for a few hours.
    Also, the way that our society has developed, I will smile, nod, and say "hello" to strangers on the street, but always leave it at that. I am sure that many walk past and think "he wasn't all that friendly." They are probably right, but at least I was pleasant to them and did not rob them! Heck, I will usually tell telemarketers, "No, but thank you for your generous offer on that time-share... "
    Hunt

  • Regular expressions with boolean connectives (AND, OR, NOT) in Java?

    I'd like to use regular expression patterns that are made up of simple regex patterns connected via AND, OR, or NOT operators, in order to do some keyword-style pattern matching.
    A pattern could look like this:
    (.*Is there.*) && (.*library.*) && !((.*badword.*) || (^$))
    Is there any Java regex library that allows these operators?
    I know that in principle these operators should be available, since Regular languages are closed under union, intersection, and complement.

    AND is implicit,
    xy -- means x AND yThat's not what I need, though, since this is just
    concatenation of a regex.
    Thus, /xy/ would not match the string "a y a x",
    because y precedes x.So it has to contain both x and y, but they could be
    in any order?
    You can't do that easily or generally.
    "x.*y|y.*x" wouldll work here, but obviously
    it will get ugly factorially fast as you add more
    terms.You got that right: AND means the regex operands can appear in any order.
    That's why I'm looking for some regex library that does all this ugly work for me. Again, from a theoretical point of view, it IS possible to express the described semantics of AND with regular expressions, although they will get rather obfuscated.
    Unless somebody has done something similar in java (e.g., for C++, there's Ragel: http://www.cs.queensu.ca/~thurston/ragel/) , I will probably use some finite-state-machine libraries and compile the complex regex's into automata (which can be minimized using well-defined operations on FSMs).
    >
    You'd probably just be better off doing multiple
    calls to matches() or whatever. Yes, that's another possibility, do the boolean operators in Java itself.
    Of course, if you
    really are just looking for literals, then you can
    just use str.contains(a) && !str.contains(b) &&
    (str.contains(c) || str.contains(d)). You don't
    seem to need regex--at least not from your example.OK, bad example, I do have "real" regexp's in there :)

  • Help with java regular expressions

    Hi all ,
    i am going to match a patternstring against an input string and print the result here is my code:
         import java.util.regex.*;
         import java.util.*;
         public class Main {
              private static final String CASE_INSENSITIVE = null;
              public static void main(String[] args)
              CharSequence inputStr = "i have 5 years FMCG saLEs exp on java/j2ee and i worked on java and j2ee and 2 projects on telecom java j2ee domain with your  with saLEs maNAger experience of java j2ee and c# having very good  on c++ exposure in JAVA"
             String patternStr = "\"java j2ee\" and \"c#\"";
              StringTokenizer st = new StringTokenizer(patternStr,"\",OR");
             Matcher matcher=null;
              while(st.hasMoreTokens()){
                   String s=st.nextToken();
                   Pattern pattern = Pattern.compile(s,Pattern.CASE_INSENSITIVE);
               matcher = pattern.matcher(inputStr);
               while (matcher.find()) {
                  String result = matcher.group();
                 if(!result.equalsIgnoreCase(" "))
                             System.out.println("result:"+result);
         when i compile this code i am getting the expected result...ie
    result:java j2ee
    result:java j2ee
    result: and
    result: and
    result: and
    result: and
    result: and
    result: and
    result:c#
    but when i replace String patternStr = "\"java j2ee\" and \"c#\""; with
    String patternStr = "\"java j2ee\" and \"c++\""; i am just getting c in the result instead of c++ ie i am getting result :
    result:java j2ee
    result:java j2ee
    result: and
    result: and
    result: and
    result: and
    result: and
    result: and
    result:C
    result:c
    result:c
    result:c
    result:c
    result:c
    result:c
    In the last lines i should get result:c++ instead of result: c
    Any ideas please
    Thanks

    In the last lines i should get result:c++ instead of result: cThe regular expression parser considers the plus sign '+' a special
    character; it means: one or more times the previous regular expression.
    So 'c++' means one or more 'c's on or more times. Obviously you don't
    want that, you want a literal '+' plus sign. You can do that by prepending
    the '+' with a backslash '\'. Unfortunately, the javac compiler considers
    a backslash a special character and therefore you have to 'escape'
    the backslash also, by adding another backslash. The result looks
    like this:"c\\+\\+"kind regards,
    Jos

  • Rplacing space with &nbsb; in html using regular expressions

    Hi
    I want to replace space with &nbsb; in HTML.
    I used  the below method to replace space in my html file.
    var spacePattern11:RegExp =/(\s)/g; 
    str= str.replace(spacePattern," "
    Here str varaible contains below html file.In this html file i want to replace space present between " What number does this  represents" with &nbsb;
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B> What number does this Roman numeral represents MDCCCXVIII ?</B></FONT></P></TEXTFORMAT></b>
    </body>
    </html>
    But by using the above regular expression i am getting like this.
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head><body>
    <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P A LIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0 " KERNING="0"><B> What number does this represents</B></FONT></P></TEXTFORMAT></b>
    </body>
    </html>
    Here what happening means it was replacing space with &nbsb; in HTML tags also.But want to replace space with &nbsb; present in the outside of the HTML tags.I want like this using regular expressions in FLEX
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>What number does this represents</body>
    </html>
    Hi,Please give me the solution to slove the above problem using regular expressions
    Thanks in Advance to all
    Regards
    ssssssss

    sorry i missed some information in above,The modified information was in red color
    Hi
    I want to replace space with &nbsb; in HTML.
    I used  the below method to replace space in my html file.
    var spacePattern11:RegExp =/(\s)/g; 
    str= str.replace(spacePattern," "
    Here str varaible contains below html file.In this html file i want to replace space present between " What number does this  represents" with &nbsb;
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B> What number does this Roman numeral represents MDCCCXVIII ?</B></FONT></P></TEXTFORMAT></b>
    </body>
    </html>
    But by using the above regular expression i am getting like this.
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head><body>
    <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADIN G="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B33 3C" LETTERSPACING="0" KERNING="0"><B> What number does this represents</B></FONT></P></TEXTFORMAT></b>
    </body>
    </html>
    Here what happening means it was replacing space with &nbsb; in HTML tags also.But want to replace space with &nbsb; present in the outside of the HTML tags.I want like this using regular expressions in FLEX
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>What&nbsb;number&nbsb;does&nbsb;this&nbsb;represents</body>
    </html>
    Hi,Please give me the solution to slove the above problem using regular expressions
    Thanks in Advance to all
    Regards
    ssssssss

Maybe you are looking for

  • Error during Creation of PO in Automatic accnt Determination

    HI GUYS, while creating automatic account determination i encountered a error while creating a Purchase order ME21N..... Pleas help me out guys error : Account assignment mandatory for material 300001003 (enter acc. ***. cat.) Regards Jino

  • Signal booster

    i was wondering if there is a device that helps improve my cell phone (IPhone) signal? When I send a text or call anyone from my house I am unable to reach anyone and or the texts don't go through until I get closer to town... Thanks

  • Problems with ALSA and OSS

    Hi. I'm a ArchLinux user and I have been having problems with my audio, specifficaly the microphone. My microphone works well with Audacity and I use it for speaking trough TeamSpeaker and since TeamSpeak still uses OSS I installed alsa-oss and added

  • ACS 5.1 backup via nfs issues

    Hi all, we ran into problems when launching an immediate backup via nfs: server is windows (nfs share), ACS is 5.1.0.44 windows log files show successful nfs mount/unmount when we try to save the ACS backup to a nfs repository but ACS reports that th

  • Deleting a bbm contact from BB Z10

    i have tried it all, please help, how do i delete a bbm contact from BB Z10? Solved! Go to Solution.