Help with regex

Hi,
I have an expression like this
<select name="contact_list">
<option value="SS109445168429566">Mark
<option value="SS109445173826096">Keith
</select>
this is not in its entire state, i have trimmed the expression to make it a bit readable
no what i want is both the options value to be extracted and stored in a value i am using the pattern like this to do the same
pattern="(?s)(?i)<option value="(.*?)""
but i am always getting th first value only, whereas i want both the values.
Can anyone help me on this.
Thank you in advance

How are you using the regex?  Pattern p = Pattern.compile("(?is)<option value=\"(.*?)\"");
  Matcher m = p.matcher(input);
  while (m.find())
    System.out.println("value is " + m.group(1));
  }That should work.

Similar Messages

  • Help with REGEX to block invalid characters

    I have a regex that is used to block unusual characters from being entered into a user name, so they can put pipes etc in there, I just want 0-9 and a-z (upper or lowercase), but I just noticed that it's not working. I am not up to speed on regex, I took this from somewhere else
    here is the expression:
    <cfif len(trim(ReReplaceNocase(form_username, '^[A-Za-z][A-Za-z0-9_]*', '', 'ALL'))) gt 0>
    It is failing when I enter 2kljlkll3456 as the username
    Anybody have any idea why it's not working?
    After posing this I found out that the issue is that it does not allo me to have a username that starts with a number, only a letter, anybody have any idea how to fix that?
    Thanks
    Mark

    Hey Dan,
    I found a link that explained how the regex is actually formed which helped!
    http://stackoverflow.com/questions/336210/regular-expression-for-alphanumeric-and-undersco res
    Now I have managed to get a basic understanding of how they are formed the fix was easy
    I had:
    <cfif len(trim(ReReplaceNocase(form_username, '^[A-Za-z][A-Za-z0-9_]*', '', 'ALL'))) gt 0>
    But should have had
    <cfif len(trim(ReReplaceNocase(form_username, '^[A-Za-z0-9_]*', '', 'ALL'))) gt 0>
    Simply removing [A-Za-z] from the start fixed it. I get it now ... so the first section defined the first character which was restricted to A-Za-z only.
    I'll mark this as answered
    Thanks
    Mark

  • Further help with regex

    Hi,
    I want to detect the presence of "fromCharCode" in a String.
    But only when it is not preceded by "String." and not followed by "(34)".
    I have already managed to do the "String." with this regex: (?<!string\.)fromCharCode --> uses the negative look behind
    This will detect the "fromCharCode", but not when it is preceded by "String.".
    But I don't know how to do the "(34)" ?
    Can somebody help me with this?

    thanks, but the problem with this regex now is that "fromCharCode" is not detected in the String fromCharCode(34) and the String String.fromCharCode.
    The text "fromCharCode" must only be detected when not preceded by "String." AND not followed by "(34)".
    Can you do this?

  • Need help with Regex

    Still trying to solve a problem in Dreamweaver - and think that using Regex is the way to go - but never used it before
    I have 2 tables on 4000 pages and want to delete 1 table from each page but they have different links and content etc
    The 2 tables on each page  are also distinguished by different table widths
    If the table I want to delete looks like this example below - what Regex do I use to make the find and replace delete only the table with <table width=100%>
    <table width="100%"><tr><td><a href="aberley.htm"><font size="-7">aberley</font></a></td></tr></table>
    Many thanks

    Thanks Nancy O - you are a Star - have tried it out and it worked perfectly
    - and this will new piece of knowledge will save me many many hours of work
    I had no previous knowledge of that Find and Replace Special Tags option
    Thanks again for your help - it is greatly appreciated

  • Help with regex. How to escape "|"

    Hi, this is my code:
    String line = "00001740 00 a 01 able 0 003 = 04866033 n 0000 = 05262099 n 0000 ! 00002062 a 0101 | (usually followed by `to') having the necessary means or skill or know-how or authority to do something; "able to swim"; "she was able to program her computer"; "we were at last able to buy a car"; "able to get a grant for the project"  ";
    //I want to capture with group(0) only the first half og the line, that preceeding "|".
    //Could anyone help me figure out why this piece of code does not work ?
    String patternStr = "(.*?)|(.*?)";
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(line);
        boolean matchFound = matcher.find();
        if (matchFound){
             relLine  = (String)matcher.group(0);
             System.out.println("LINE " + relLine);
             } else {
            System.out.println("ATTENTION MATCH WAS NOT FOUND FOR LINE " + line);
                  }

    "\\|"You need to use the backslash.
    However, since backslash is also a special character in a Java String literal, you need two of them. The first one gets eaten by the compiler, escaping the second one, which is used by regex to escape the pipe.

  • Please help with regex

    Hi
    I want regex for following condition:(case insensitive)
    1)First letter must be always an alphabet(case insensitive).
    2)It should be maximum of 64 characters.
    3)Rest all letter can be number alphabets and underscore.(case insensitive)
    4)Defines an inverse domain name like "com.sun.yyyy.xxxx". Restricted to max 20 dot-separated identifiers of max. 30 chars each.
    5)After . there must not be number for eg com.sun.1awt is not valid.

    Not properly tested, but here goes:
    // some tests
    String[] tests = {
      "com.sun.yyyy.xxxx",
      "com.sunsd.yy435yy.xxxx",
      "com.sun.yyyy.5xxxx",
      "com.sun.yyyeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey.xxxx",
      "com.sun.yyyy..xxxx"
    // An atom must start with a letter follwed by 0 to 29 numbers, letters or underscores
    String atom = "[a-z][a-z0-9_]{0,29}";
    String regex =
      "(?i)"+                  // ignore case
      "(?=^.{1,64}$)"+         // must be between 1 and 64 characters
      atom+                    // start atom
      "(?:\\."+atom+"){0,19}"; // followed by 0 to 19 atoms with a '.' in front of it
    for(String t: tests) {
      System.out.println(t.matches(regex)+" -> "+t);
    }

  • I need help with Regex, please !

    Hello,
    I would like to build the following expression: I want matcher a succession of words (e.g. separated by 1 space), but not containing a specifc word.
    Let's me give you an example to be more explicit:
    String regex = "([\\S]+ )+"; that exprisses a succession of words, but I want to supplement my regular expression (regex) to indicate that I don't want the word "MANU" for example.
    string input = "TUTU TATA TITI MANU TOTO TITI TATA MANU"
    I would like the following results:
    "TUTU TATA TITI MANU"
    "TOTO TITI TATA MANU"
    but not these one:
    "TUTU TATA TITI MANU TOTO TITI TATA MANU"
    Thank you for your answers

    Right, I forgot that the matcher would bump along and try "(?!MANU\\b)\\S+" at the second letter of each group. The solution is to use \w instead of \S, and anchor the match at the beginning of the word with \b:import java.util.regex.*;
    public class Test
      public static void main(String[] args)
        String target = "TUTU TATA TITI MANU TOTO TITI TATA MANU";
        Pattern p = Pattern.compile("(?!MANU\\b)\\b\\w+(?: (?!MANU\\b)\\b\\w+)*");
        Matcher m = p.matcher(target);
        while (m.find())
          System.out.println(m.group());
    }

  • Help with regex pattern matching.

    Hi everyone
    I am trying to write a regex that will extract each of the links from a piece of HTML code. The sample piece of HTML is as follows:
    <td class="content" valign="top">
         <!-- BODY CONTENT -->
    <script language="JavaScript"
    src="http://chat.livechatinc.net/licence/1023687/script.cgi?lang=en&groups=0"></script>
    <a href="makeReservation.html">Making a reservation</a><br/>
    <a href="changeAccount.html">Changing my account</a><br/>
    <a href="viewBooking.html">Viewing my bookings</a><br/>I am interested in extracting each link and the corrresponding text for that link into groups.
    So far I have the following regex <td class="content" valign="top">.*?<a href="(.*?)">(.*?)</a><br>However this regex only matches the first line in the block of links, but I need to match each line in the block of links.
    Any ideas? Any suggestions are appeciated as always.
    Thanks.

    Hi sabre,
    thanks for the reply.
    I am already using a while loop with matcher.find(), but it still only returns the first link based on my regex.
    the code is as follows.
    private static final Pattern MENU_ITEM_PATTERN = compilePattern("<td class=\"content\" valign=\"top\">.*?<a href=\"(.*?)\">(.*?)</a><br>");
    private LinkedHashMap<String,String> findHelpLinks(String body) {
        LinkedHashMap<String, String> helpLinks = new LinkedHashMap<String,String>();
        String link;
        String linkText;
          Matcher matcher = MENU_ITEM_PATTERN.matcher(body);
          while(matcher.find()){
            link = matcher.group(1);
            linkText = matcher.group(2);
            if(link != null && linkText != null){
              helpLinks.put(link,linkText);
        return helpLinks;
    private static Pattern compilePattern(String pattern) {
        return Pattern.compile(pattern, Pattern.DOTALL + Pattern.MULTILINE
            + Pattern.CASE_INSENSITIVE);
      }Any ideas?

  • Help with RegEx and Textinput

    I have the following method:
    public function handleKeyPress(event:KeyboardEvent):void {
    //trace("Key pressed: "+event.keyCode+","+event.charCode);
    var testTest:String = cComponent.cInput.text +
    String.fromCharCode(event.keyCode);
    trace("Text tested: \""+testTest+"\"");
    // See if the user typed '/' followed by a number and a
    space
    if(testTest.match(new RegExp("\/[0-9]*\s"))) {
    // User typed '/### '
    // TODO: Get bpname and do something here...
    cComponent.cInput.text="";
    event.stopImmediatePropagation();
    Basically, I need to match on the pattern "/### ", where ###
    is any series of numbers, do something, then clear the TextInput,
    but I can't seem to get the RegEx right. I have tried several
    different ones, including '\/\d*\s' and '\/[0-9]* ', but nothing
    seems to work.
    On top of this, the call to cComponent.cInput.text="" doesn't
    wipe the value of the TextInput field either.
    Can someone point me in the right direction?

    This got me mostly working. It's still matching on all
    strings that start with / then some number, but I still cannot get
    that TextInput to clear. From the code I call:
    cComponent.cInput.text="";
    It doesnt throw an error, but it doesn't clear the text
    either.

  • Help with Regex for service-http

    Hi folks,
    I'm trying to write a custom sig to match on certain values found in an HTTP GET request. The sig uses the service-http engine for TCP on standard WEBPORTS. For the sake of this example, lets say the string I'm looking for it:
    first=<somedata>&second=<somedata>&third=<somedata>
    In other words, if I see those three argument names (first, second, and third) then I want the sig to fire. The actual values of <somedata> is irrelevant.
    The RegEx I'm using is:
    ((first=).*(&second=).*(&third=).*)
    However the sig is firing on requests that just match on seeing "&third" in the HTTP GET. Again, I need -all three- arguments present for the sig to fire.
    Any suggestions? Am I on the right track with the regex?
    Thanks!!

    Ok, replying to my own post here, but I was able to resolve this issue. The regex does work as designed. I think to be safe I should add brackets to make it case-insensitive (e.g. (([Ff][Ii][Rr][Ss][Tt]=) ) but otherwise this matches the intended traffic.

  • Help with regEx or any other idea ....

    my program reads from the keyboard... if there is a character like K the description is printed ... but if there is also a number between 2.....10 and K then the number should be printed too
    example :
    reading from keyboard: 4K
    then 4 + description of K should be printed
    I tried this:
    else if(n.equals("S") && notationShort.containsKey("S")|| (n.equals.{2,10})
         {System.out.println(notationShort.get("S"));}but its not working ... can someone help please?
    thank you in advance!

    sabre150 wrote:
    new_in_JAVA_but_soon_not wrote:
    not sure if someone understand my question ?? or no one know how to solve it?
    hmmmHmmm - I certainly don't fully understand what you are trying to do. It seems to me you want to test for some digits followed by one of a set of letters. If this is the case then what set of letters and how many digits. Also, can other things come before the digits or follow the letter?
    You need to think a bit more about your questions if you expect any answer other than a wild guess.ok how can i write in regular expression the range between 2..10 ?

  • Need help with Regex replace in DW

    I'm converting a document to HTML that came with mixed case image filenames.  Our standards say that all filenames must be lowercase, so I used a CF script to convert them, but the src links in the HTML doc tag still shows the uppercase name.
    I planned to do something like this:
    Find:
    <img src="(.+?)" alt="(.+?)" />
    Replace:
    <img src="$1" alt="$2" />
    but I can't seem to get it to lowercase the $1 argument.  I've tried \L and all the normal things, but I just get the literal replacement.  Any tips?

    Use Regular Expressions
    "Big_Slick" <[email protected]> wrote in
    message
    news:f0ip6t$ee8$[email protected]..
    >I need to know how to Find/Replace for more than one tag
    at a time
    >(I.E--Search
    > for <table>, <tr>, and <td> or
    and and remove the code) As it is
    > right
    > now, it will only search for one tag at a time but I
    would assume DW can
    > handle
    > this kind of thing.
    >
    > Thanks in advance.
    >

  • Pls help with RegEx

    Hello,
    I can't figure out how to write a simple regex.
    For example I have a String ("12345678") and I'd like to find out whether my String contaings "456".String str1 = "12345678";
    String str2 = "456";
    System.out.println(str1.matches(?)); // what is the right regex to find out if str1 contains str2?

    For such a simple example, regex is overkill. You could just test for String.indexOf("456") >= 0
    However, to answer your question, the expression would be:
    .*456.*

  • ACE HTTP Probe with regex

    ACE HTTP Probe with regex
    Hi,
    I'm trying to setup a HTTP probe with expected string rather then a code (config below). I do a GET for the page then a search for a string in the response however it's not working, as probe appears as failed.
    I've tested the connection to the server by using telneting and then looking at the page displayed to make sure the string I want to match is in the response.
    probe http HTTP-PROBE
    port 43050
    interval 30
    passdetect interval 30
    passdetect count 1
    request method get url /action=help
    open 43050
    expect regex action=help
    Q. Is there anything wrong with this configuration and what I'm trying to achive?
    Thanks,
    Pritesh

    Use "expect status" under probe config. expect regex doesnt work if expect status is not configured.
    expect regex work flawlessly with static pages. It doesnt work all the time with dynamic pages.
    Specially if "content-length" header is missing from Server response.
    Hope it helps
    Syed Iftekhar Ahmed

  • Problem with regex

    sorry about my english.
    i'm working with large xml file which it data like this
    (this is sample data)
    <DOCTYPE lewis SYSTEM "lewis.dtd">
    <REUTERS TOPICS="NO" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20436" NEWID="21001">
    <DATE>19-OCT-1987 15:37:46.03</DATE>
    <TOPICS></TOPICS>
    <PLACES></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    F
    f2882reute
    f f BC-CITYFED-FINANCI   10-19 0013</UNKNOWN>
    <TEXT TYPE="BRIEF">
    ******<TITLE>CITYFED FINANCIAL CORP SAYS IT CUT QTRLY DIVIDEND TO ONE CENT FROM 10 CTS/SHR
    </TITLE>Blah blah blah.
    </TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>crude</D><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>i'm try to remove article with no topic or two or more topic.
    this is my code.(sorry for not clean the code many testing in it)
    package reuterxmlextraction;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.regex.Pattern;
        public static void main(String[] args) throws IOException {
            int traningcount = 0;
            int testingcount = 0;
            int notopicex = 0;
            int multitopicex = 0;
            int totaltest = 0;
            int totaltrain = 0;
            int countarticle = 0;
            String finalOutput = "";
            File rfile = new File(args[0]);
            try {
                // Open the file that is the first
                // command line parameter
                FileInputStream fstream = new FileInputStream(rfile);
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in), 1024 * 100);
                String strLine;
                String preOutput = "";
                ArrayList<String> preOutputmod = new ArrayList<String>();
                //Read File Line By Line
                //           while ((strLine = br.readLine()) != null) {
                //preOutput += strLine;
                //System.out.print(strLine);
                int len = (int) (rfile.length());
                byte buf[] = new byte[len];
                fstream.read(buf);
                fstream.close();
                preOutput = new String(buf);
                //System.out.println(preOutput);
                totaltest = count(preOutput, "LEWISSPLIT=\"TEST\"");
                totaltrain = count(preOutput, "LEWISSPLIT=\"TRAIN\"");
                int tempindex = 0;
                while (preOutput.indexOf("<REUTERS ", tempindex) != -1) {
                    //        while(tempindex == 0){
                    int a = preOutput.indexOf("<REUTERS ", tempindex);
                    //System.out.print(a +"\n");
                    int b = preOutput.indexOf("</REUTERS>", tempindex) + 10;
                    //System.out.print(b +"\n");
                    char pre[] = new char[b - a];
                    preOutput.getChars(a, b, pre, 0);
                    preOutputmod.add(String.valueOf(pre));
                    tempindex = b;
                    countarticle++;
                int loop = 0;
                while (loop < preOutputmod.size()) {
                    if (preOutputmod.get(loop).matches(".+<TOPICS>\\s*</TOPICS>.+")) {
                        preOutputmod.remove(loop);
                        notopicex++;
                        continue;
                    if (Pattern.matches(".+[<TOPICS>]?[<D>.+</D>]{2,}</TOPICS>.+\\s*", preOutputmod.get(loop))) {
                        preOutputmod.remove(loop);
                        multitopicex++;
                        continue;
                    } else {
                        finalOutput += preOutputmod.get(loop);
                    loop++;
            } catch (Exception e) {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            if (args[1] != null) {
                File f = new File(args[1]);
                Writer output = new BufferedWriter(new FileWriter(f));
                try {
                    //FileWriter always assumes default encoding is OK!
                    output.write(finalOutput);
                } finally {
                    output.close();
        static int count(String base, String searchFor) {
            int len = searchFor.length();
            int result = 0;
            if (len > 0) {  // search only if there is something
                int start = base.indexOf(searchFor);
                while (start != -1) {
                    result++;
                    start =
                            base.indexOf(searchFor, start + len);
            return result;
    }problem is that regex in my code don't work.
    i'm not good with regex.
    please help.
    ps.the xml i mentioned is reuter-21578 dataset total size approx 27mb

    Just saying "doesn't work" is meaningless. You need to provide details about exactly what went wrong.
    However, that's irrelevant here, since this is NOT a good job for regex. Use an XML parser.

Maybe you are looking for