REReplace / Regex Help

I have to replace single quote marks in a html file with doubles without changing aprosphies. All are in class='' files but some are not closed at the end. Some contain additional information. I was looking for "class='" as my replace and then "'/>" as my ending by it doesnt catch those correctly with a stye also in the string.
I want to use regex to look for class='%' but dont know if there is a way to replace the wildcard content back and only replace the single quotes that surround it.
I.E. <class='page_general_content' /> = <class="page_general_content" /> or <class='image_body'> = <class="image_body" />
or my personal favorite <div class='media_wrapper' style='width:300px;'> = <div class="media_wrapper" style="width:300px;"> where i have to look for a wildcarded style too.
Any ideas on how to do this. Of course it came in this morning and needs to be done today so code examples would be highly appreciated. Thanks!

wmkolcz wrote:
I have to replace single quote marks in a html file with doubles without changing aprosphies.[...]
or my personal favorite <div class='media_wrapper' style='width:300px;'>
Hi wmkolcz,
Regex isn't necessary.  Here is an example:
<cfsavecontent variable="html">
  <div class='media_wrapper' style='width:300px;'>foobar's</div>
</cfsavecontent>
<cfset xml = xmlParse(html) />
<cfdump var="#right(xml, len(xml)-39)#" />
Thanks,
-Aaron

Similar Messages

  • [regex help]Find EXACT characters in a String.

    Ok, i got this so far ...
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Testing2 {
        public static void main(String[] args) {
            Pattern p = Pattern.compile("[wati]");
            String text = "water";
            Matcher m = p.matcher(text);
            if (m.find()) {
                System.out.print("Found !");
    }With that code i got a match, but i ONLY want to find a match if the String matches the EXACTS characters in the Pattern ...
    in this case i got, 'w' 'a' 't' 'i', 'w' 'a' 't', are in water, but 'i' NOT, so i don't want to have a match !
    i don't know how to acomplish this :(
    hope you can help me, thanks in advance :D

    Username7260 wrote:
    Ok, i got this so far ...
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Testing2 {
    public static void main(String[] args) {
    Pattern p = Pattern.compile("[wati]");
    String text = "water";
    Matcher m = p.matcher(text);
    if (m.find()) {
    System.out.print("Found !");
    }With that code i got a match, but i ONLY want to find a match if the String matches the EXACTS characters in the Pattern ...
    in this case i got, 'w' 'a' 't' 'i', 'w' 'a' 't', are in water, but 'i' NOT, so i don't want to have a match !
    i don't know how to acomplish this :(AFAIK there's no syntax in regular expressions to accomplish this. Try turning your string into a character array, sorting it, and then do a simple comparison.

  • In need of Regex help

    Hi,
    I've never used Regex before, and since I currently need to use it for a command-line parser in my server application I thought that I should try to see if anyone feels kind enough to take a couple of minutes and help me out (The regex tutorial is way complicated to get down and study for this tiny purpose).
    I need a regex that will be used with String.split to chop up an input string.
    If the string looks like: get 2.worm from bag
    the result should be:
    get
    2.worm
    from
    bag
    If the string looks like: cast "magic missile" 3.turtle
    the result should look like:
    cast
    magic missile
    3.turtle
    In short, it should never return any whitespace if it is not delimitered with ":s.
    Does it make any sense?
    Grateful for any help I can get.
    Sincerely
    /Viktor Klang

    Try this:
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Parser {     
         private static String REGEX          = "([^\\s\"]+)|(\"[^\"]+\")";
        private static String INPUT          = "cast \"magic missile\" 3.turtle";
        private Pattern pattern;
        private Matcher matcher;
        private List lineParts = new LinkedList();
         public void processString(String input) {
            String token = null;
              Integer value = null;
            while ( matcher.find() ) {
                 token = input.substring( matcher.start(), matcher.end() );
                 token = token.replaceAll( "\"", "" );
                 lineParts.add( token );
         public void printResults() {
              Object token = null;
              Integer value = null;
              for (Iterator iter = lineParts.iterator(); iter.hasNext();) {
                   String element = (String) iter.next();
                   System.out.println( element );
         public void doIt() throws IOException {
              pattern = Pattern.compile( REGEX );          
              matcher = pattern.matcher( INPUT );
              processString( INPUT );
              printResults();
         public static void main(String[] args) throws IOException {
              Parser parser = new Parser();
              parser.doIt();
    }

  • RegEx help requested.

    Hello, All.
    I am new to Java and I am not much familiar with Java regExp package as well. I am looking into it though. I have a specific question related to Reg Exp creation.
    We are in need of parsing a string like "XXX > 6 && YYY> 10" [Meaning variable XXX is greater than 6 and variable YYY is greater than 10 ] please note that this string/condition is dynamic and we need to support the normal operators and AND and OR operator for clubbing the condition.
    We are just thinking that whether regex will solve our problem? if so how it can be recommended used and what would be the sample of regex grammer?
    Thanks a lot in advance for your help.
    Best Regards,
    Prasanna.

    novice_questions wrote:
    Thanks for your reply. It may not have brackets in side the expression.
    LHS = will contain alphabets/digits and . [xxx.a1]
    RHS = [0-9]
    Operator can be [>,<]
    But this expression can be combined [AND,OR]
    like [exp]+[AND,OR][exp] ..some thing like this.
    Thanks,
    Prasanna.As already mentioned: you can't use regex for this. You either have to write your own parser or, if the expression stay as simple as you posted, use the existing script engine from Java 1.6.
    Here's a small demo:
    import javax.script.*;
    public class Test {
        public static void main(String[] args) throws Exception {
            ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
            String expression = "a > 2 && b < 2";
            engine.put("a", 3);
            engine.put("b", 1);
            System.out.println(engine.eval(expression));
    }

  • Flex Regex Help

    Hi there,
    I have a regular expression that is used to validate names in my application. It's intended to only allow alphanumeric names and spaces. My trouble started when I tried to modify it to also accept other unicode characters (umlauts and whatnot) On the java side of my app the following regex works great:
    "^(\\p{L}+\\p{M}*|\\d+)+\\s*((\\s+\\p{L}+\\p{M}*)*|(\\s+\\d+))*$"
    But due to, I'm guessing, lack of support for \p in AS3's regex engine this doesn't work. Does anyone know how to modify this regular expression to allow flex to recognize valid unicode characters?
    Here's one that I also thought would work but didn't maybe this will be helpful as a starting point.
    "^(\\w+|\\d+|[\\x00-\\x80]+)+\\s*((\\s+\\w+)*|(\\s+\\d+)|(\\s+[\\x00-\\x80]+)*)*$"
    Thanks in advance for any help.

    http://examples.adobe.com/flex3/componentexplorer/explorer.html
    http://examples.adobe.com/flex3/consulting/styleexplorer/Flex3StyleExplorer.html#

  • Regex help

    Hello i need some help with regex to do the following
    String to get:
    http://www.domain.com/images/pic.jpg
    String to search:
    <img src="
    http://www.domain.com/images/pic.jpg"
    width="202" height="62" />
    Using the following regex expression:
    <img src="([^>]*[^/]?)>
    So far when i run this it grabs the following:
    http://www.domain.com/images/pic.jpg"
    width="202" height="62" /
    Any help is very much appreciated.

    Mrs. Man wrote:
    > Hello i need some help with regex to do the following
    >
    > String to get:
    >
    http://www.domain.com/images/pic.jpg
    >
    > String to search:
    > <img src="
    http://www.domain.com/images/pic.jpg"
    width="202" height="62" />
    >
    > Using the following regex expression:
    > <img src="([^>]*[^/]?)>
    <img src="([^"]*)"
    Mack

  • Regex help wanted

    OK - I have a CSV file where each cell value is surrounded by double-quotes. What's more, the values can have commas in them (which are not escaped in anyway). The values can also be empty. So if I have the line
        "a,b","c","","d,e,f"I want to get 4 cells here:
        a,b
        c
        <the empty String>
        d,e,fand I'm trying to do this with java.util.regex - I've tried using (\".*\") - and then getting the groups returned (as the cells) but this matches no groups!
    Yes I've read the docs for Pattern, yes I've searched around (etc etc) and yes I've asked my colleagues; we're all useless at regex. Any help would be great!

    sabre150 - thanks, this is a great help. I've used groups before and, quite frankly, I'm not sure how because now they don't seem to be working how I thought they did:
                String line = "\"a,b\",\"c\",\"\",\"d,e,f\"";
                Pattern pattern = Pattern.compile("\"([^\"]*)\"");
                Matcher matcher = pattern.matcher(line);
                //This just returns 1 instead of the 4 I was expecting
                //group(1) is null
                int groupCount = m.groupCount();
                String[] cells = new String[groupCount];
                for (int i = 1; i <= groupCount; i++) {
                    cell[i-1] = m.group(i);
                }Is how I've been using the group facility on the Matcher. Trouble is, it doesn't work; evidently it doesn't behave as I was expecting it to! Could you elaborate on how it works and how (if at all possible) I can get the pattern to tell me how many cells it will find up front?

  • Regex help for URL rewriting

    I have the following regular expression for rewriting a URL (from existing code which I had to make some quick changes)
    String     regex = "s#(href|src|url|action|background)=(\"?)(/|" + "http:originalserver.com" +"/|http.?://" + "originalserver.com"+ ")([^\">]*?)(\"?)#$1=$2" + "myserver.com" + "/$4$5#gis";
    which does a URL rewrite and changes the URL from something like
    src="http://originalserver.com/images/someimage.gif" to
    src="http://myserver.com/proxy/images/someimage.gif"
    Now I want to change this regex to add some parameters to the URL. ie.
    case 1:
    href="http://www.originalserver.com/index.htm"
    to
    href="http://www.originalserver.com/index.htm?myParam1=myValue1
    case 2:
    href="http://www.originalserver.com/index.htm?originalP1=originalV1"
    to
    href="http://www.originalserver.com/index.htm?originalP1=originalV1&myParam1=myValue1"
    How can I change the regex to do this. As I have to do this fast and not an expert in Regex, any help would be appreciated.

    Hi,
    try this :
    - first set delimiter (? or &) to append your parameters :
    char delimiter = '\?';
    String myParams = "myParam1=myValue1";
    Pattern p = Pattern.compile( "\?" );
    Matcher m = p.matcher( url );
    if( m.matches() )
    delimiter = '\&'; // not sure ampersand needs to be "backslashed"
    - then use the modified regex
    String regex = "s#(href|src|url|action|background)=(\"?)(/|" + "http:originalserver.com" +"/|http.?://" + "originalserver.com"+ ")([^\">]*?)(\"?)#$1=$2" + "myserver.com" + "/$4$5" + delimiter + myParams + "#gis";

  • Regex help for SQL update statement

    Hello,
    need help from IPS regex guru - trying to build the signature to detect SQL update statement in HTTP requests.
    1) Am I correct with regex below specified as Request-Regex?
    [Uu][Pp][Dd][Aa][Tt][Ee]([%]20|[+])[\x20-\x7e]+[Ss][Ee][Tt]([%]20|[+])[\x20-\x7e]+=
    2) How do I make sure that it detects 'Update' in URI and Arguments only and not in the body on entire webserver response (currently looks like the case)?

    1) It looks correct to me
    2) Typically, the "service HTTP" engine is used to inspect requests and the "TCP string" engine is used to inspect HTTP server responses. If you only want to inspect requests, use the service HTTP engine.

  • Regex Help: Word not following by another word

    Hi,
    I am trying to write a regex that would return me lines containing a given string but it should not be followed by another.
    Lets say the lines in the sample file are as follows:
    ABC.EXE
    ABC.PDF
    ABC.TXT
    ABC.DOC
    RegEx I used is as follows:
    ^.*ABC.*(?!EXE)$
    I want the RegEx to match all lines except the first, looks like the look ahead is not work.

    Yes, this is what I was looking for.
    Only problem and if you look at the RegEx I used
    initially, I wanted to look at all strings that start
    with ABC.
    So basically I want to exclude ABC.EXE and also
    ABCDE.EXE. How can I do this?
    Thanks in advance for your help.
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#startsWith(java.lang.String)

  • Xml regex help - can't use xml parser

    Hi,
    I receive xmls from a legacy system and use JAXB to parse these xml's into java objects.
    The xml looks roughly like this:
    <root-Tag>
       <general-Info-Tag-1>blah</<general-Info-Tag-1>
       <general-Info-Tag-2>blah</<general-Info-Tag-2>
       <general-Info-Tag-3>blah</<general-Info-Tag-3>
       <entry-Tag>
          <entry-info-Tag-1>info</entry-info-Tag-1>
          <entry-info-Tag-2>info</entry-info-Tag-2>
           etc...
       </entry-Tag>
       <entry-Tag>
          <entry-info-Tag-1>info</entry-info-Tag-1>
          <entry-info-Tag-2>info</entry-info-Tag-2>
           etc...
       </entry-Tag>
    </root-Tag>The xml contains a root tag.
    The root element contains some general info tags and entry tags.
    The entry elements contain some entry relevant info inside nested tags.
    It's important to note that this the xml is not nested anymore than the entry-info tags.
    My Problem:
    The info in the entry-info-tags sometimes contains illegal chars like <,>,& and is not wrapped
    properly by a CDATA section.
    So I need to find these elements and wrap them with <![CDATA[info]]> before using JAXB.
    How can I achieve this using Pattern/Matcher? I've been unsuccessful so far...
    Edited by: Samuelz on Jul 1, 2010 1:58 AM

    Heres what i've got so far:
    A helpful function to print out matches for regex on an input string:
    private static void printMathces(final String regex, final String input) {
         Pattern p = Pattern.compile(regex, Pattern.DOTALL);
         Matcher m = p.matcher(input);
         while (m.find()){
              System.out.println("found:");
              for (int i = 0; i < m.groupCount(); i++)
                   System.out.println(i + ":" + m.group(i));
    }My input string for testing:
    String s =
    "<entries>\n"+
         "<entry>\n" +
              "<TagName>sam&max</TagName>\n" +
         "</entry>\n" +
         "<entry>\n" +
              "<TagName><![CDATA[sam&max]]></TagName>\n" +
         "</entry>\n" +
    "</entries>\n";regex to get contents of TagName:
    printMatches("<(TagName)>((.*?))</\\1>+", s);
    found:
    0:<TagName>sam&max</TagName>
    1:TagName
    2:sam&max
    found:
    0:<TagName><![CDATA[sam&max]]></TagName>
    1:TagName
    2:<![CDATA[sam&max]]>regex to get content of TagName when its wrapped by CDATA
    printMathces("<(TagName)><!\\[CDATA\\[((.*?))\\]\\]></\\1>", s);
    found:
    0:<TagName><![CDATA[sam&max]]></TagName>
    1:TagName
    2:sam&maxI'm trying to build a regex that will find the contents of TagName without knowing if its already wrapped by CDATA and then replace these matches by something like <$1><![CDATA[$2]]</$1>
    How do I "combine" these 2 regular expressions?

  • Regex help please...need to grab a part of a string...

    Hi there,
    I have a dynamic form with dynamic fields and dynamic data types.
    What I want to do is check the data-type by grabbing it from the field name.
    For example, I have a field name called "formEmail[email]"
    The whole string is the field name, but I want to also extract the string between the square brackets. This will help me validate the field when it comes to submission. I will then compare it to a last of valid possibilities.
    How can I do this? I know it must require some regex but I have never looked into REGEX....my bad I know...but I promise I will in future!
    Mnay thanks,
    Mikey.

    Mikey,
    One question: Is the string 'formEmail[email]' the actual string (as opposed to being a variable that will get evaluated)?
    There are a lot of ways to go about this sort of task with regular expressions. If 'formEmail[email]' is an example of the type of strings you are searching, a regular expression along the lines of the following might be useful:
    <cfscript>
         mystring = "formEmail[email]";
         results = ReMatch( "[(\w*)]+", mystring );
    </cfscript>
    <cfdump var="#results#">
    <cfoutput>
         First match: #results[1]#<br />
         Second match: #results[2]#<br />
    </cfoutput>
    This regular expression finds all words in a string but does not match the brackets. \w is a special character that matches any word character -- including alphanumeric chars and underscores.
    The brackets used in the regular expression are also special characters for groupingt, which you can learn more about in the section of the CF WACK book mentioned JR's reply.
    If you run this snippet, you'll notice you get an array back. The first element of the array is the first match of the regexp, or the string 'formEmail', and the second element of the array is the second match of the regexp, or the string 'email'.
    This regular expression might be helpful if you don't have consistent text before the brackets but you know the string you'll search is formatted as: string[string].
    For example, the ReMatch expression above works the same for either of the strings below:
    formPhoneNumber[phone] (would return two strings: formPhoneNumber and phone)
    formEmail[email] (would return two strings: formEmail and email)
    As you delve into the world of Regular Expressions, be sure to grab RegExr, an Adobe AIR application for testing regular expressions. Very handy, especially coupled with a reading of the RegExp section in Forta's CF WACK book!
    http://gskinner.com/RegExr/desktop/

  • Regex Help - Parsing Names

    I am receiving names from another system, and I need help parsing the data as it comes in. There are common data entry errors from the other system that I want to correct as the data is imported. I am trying to formulate a regular expression to search and replace common errors.
    Example 1: A record with the last name "DE  ROSA" is imported. Note that there are two spaces between "DE" and "ROSA". I want to remove the extra spaces. This one is more straight forward.
    Example 2: A record with the last name "DE  ROSA-DE  LA  CRUZ" is imported. It's the same problem, but now there are two places in which it needs to be fixed.
    Example 3: A record with the last name "LYNDE-DE  ROSA" is imported. I want to correct the extra spaces in "DE ROSA" but not touch Lynde, which also contains "DE" at the end.
    I can't seem to create a regular expression that will find all of the scenarios that I need without including results I don't want. These are the rules I need:
    1. Search for the expression "DE" as a phrase with one or more spaces after it.
    2. The item preceding "DE" must be nothing (the beginning of the line) or a character that is not a-z or A-Z.
    It seems simple enough, but my expression either don't catch "DE" at the beginning of the string, or they catch the "DE" at the end of a last name. The names are converted to uppercase for simplified procession.
    Any help would greatly be appreciated. I tried to explain this with the simplest examples possible, but I can provide more information if that would help.

    JavaUser wrote:
    936517 wrote:
    I suggest you use JUnit if you don't already use it to verify every possible input condition is tested and passes.Thank you for the suggestion. I don't have JUnit set up for this project. I have a small program that I created, based off of the one provided in the regex tutorial, that allows me to type in a regular expression, a string I want to evaluate, and the results it produces. The regex expression I tried and the examples I could think of all worked. I also have some test data to try, once I finish my little program. I won't be able to anticipate every possible typo the users can make, but this will be an improvement over what we have now.I suspect you are reading more into 936517's post than he meant; I certainly don't think he expected you to cover all possible inputs since, being infinite, that is impossible. I think he probably meant to say you should cover a good selection of 'good' data and a good selection of 'bad' data plus all edge conditions you can think of.
    I agree with 936517 about using JUnit. It works well even for the sort of testing you are doing.

  • Regex help... Need to improve regex skills

    Hi everyone
    I m new to java.
    currently I om working an a project that requires regex for parsing.
    I am able to parse the string but I feel that regex I wrote is not efficient.
    please help me.
    String: "Oct.8, 9, 15, 16, 22, 23, 29, 30Nov.5, 6, 12, 13, 19, 20, 26, 27"
    I want to parse Oct 8 and Nov 27 (start and end of the period)
    This is the regex that i wrote.
    regex: "([a-zA-Z]+)\..*,\s*(\d+)([a-zA-Z]+).*,\s*(\d+)"

    Found this on google, maybe it will help.
    try {
            // Some examples
            DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
            Date date = (Date)formatter.parse("01/29/02");
            formatter = new SimpleDateFormat("dd-MMM-yy");
            date = (Date)formatter.parse("29-Jan-02");
            // Parse a date and time; see also
            // e317 Parsing the Time Using a Custom Format
            formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
            date = (Date)formatter.parse("2002.01.29.08.36.33");
            formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
            date = (Date)formatter.parse("Tue, 29 Jan 2002 22:14:02 -0500");
        } catch (ParseException e) {
        }

  • REGEX help in oracle 10g

    Hi,
    I have to check for non-numeric at a particular location of the usernames in my database.
    The usernames i am looking for are something like given below:
    SAMCM1
    SAMCM2
    SAMCM3
    SAMDM1
    SAMEM1
    There are other usernames which i dont want to list ..something like the ones given below:
    SAM1CM1
    SAM2CM2
    SAM4CM3
    SAM8DM1
    SAM3EM1
    How to can i achieve to get the results ( the one mentioned in my 1st listing) above using regex in oracle 10g,the one where i dont want the usernames containing a numeric value at the 4th position of the username.
    I tried but not success ,partly because my knowledge of regex is very poor.
    Regds,
    Kunwar

    WITH t AS (SELECT COLUMN_VALUE nm
                 FROM TABLE (sys.odcivarchar2list ('SAMCM1',
                                                   'SAMCM2',
                                                   'SAMCM3',
                                                   'SAMDM1',
                                                   'SAMEM1',
                                                   'SAM1CM1',
                                                   'SAM2CM2',
                                                   'SAM4CM3',
                                                   'SAM8DM1',
                                                   'SAM3EM1')))
    SELECT nm
      FROM t
    WHERE REGEXP_LIKE (nm, '^.{3}[^[:digit:]]')
    NM
    SAMCM1
    SAMCM2
    SAMCM3
    SAMDM1
    SAMEM1

Maybe you are looking for