Regular Expressions with Java Regex

Hi,
I'm playing around with regex and there's something I can't get to work. What I need, is to capture words between 2 other words and the words captured has to be higher than 5 characters, so for example:
Pattern "Just testing on something with regular expressions" and suppose I'll try to match all the words between "testing" and "regular", then only the word "something" should come out because "on" and "with" are not larger than 5 chars.
Now I'm quite new to regexps and I know that ((?<=\btesting\b).*(?=\bregular\b)) will return " on something with "
But I can't seem to come up with an expression that would only output the word "something". I've tried a few expressions like ((?<=\btesting\b)((?:[\s\w{1,3}])*(\b\w{4,}\b)*(?:[\s\w{1,3}])*)*(?=\bregular\b)) which also returns " on something with " The others I tried would either return the whole " on something with " or return "Not Found!"
Does anyone have a tip for me? I'm well aware that it's not too hard to do something like this in Java, but I'm really looking to study regular expressions and would like to accomplish this using a regular expression.
The Java program I use is the following:
C:\Program Files\Java\jdk1.5.0_16\bin>java RegexTest "((?<=\btesting\b).*(?=\bregular\b))" "Just testing on something with regular expressions"
public class RegexTest {
     public static void main(String[] args) {
          Pattern RegexCompile = Pattern.compile(args[0]);
          Matcher m = RegexCompile.matcher(args[1]);
          boolean found = m.find(); // Perhaps there's another function to find () that would do the job?
          if (found)
          System.out.println(m.group()); // Perhaps group() is not the right function for this case?
          else
          System.out.println("Not Found!");
Edited by: dli2k3 on Sep 19, 2008 11:32 AM
Edited by: dli2k3 on Sep 19, 2008 11:33 AM

You're talking about a two-stage operation: find everything between those two words, then filter out anything that's less than five letters long. There's no single regex that will accomplish all that in one step.
By the way, please use &#x7B;code} tags when you post source code.

Similar Messages

  • Regular expressions with java.util.regex

    Hello Guys,
    I wrote last time this
    * Uses split to break up a string of input separated by
    * commas and/or whitespace.
    * See: http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/
    * Change: I have slightly modified the source
    import java.util.regex.*;
    public class Splitter {
    public static void main(String[] args) throws Exception {
    // Create a pattern to match breaks
    Pattern p = Pattern.compile("[<>\\s]+");
    // Split input with the pattern
    String[] result =
    p.split("<element attributname1 = \"attributwert1\" attributname2 = \"attributwert2\">");
    for (int i=0; i<result.length; i++)
    if (result.equals(""))
    System.out.println("EMPTY");
    else
    System.out.println(result[i]);
    int res = result.length - 1;
    System.out.println("\nStringlaenge: " + res);
    I wonder, why I got an empty element in reult[0]. Have anyone an idea?
    We'll come together next time
    ... �nhan Inay ([email protected])

    What is wrong with this Pattern?
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    This time i used following Split:
    p.split("<element attributname1=\"attributwert1\" attributname2=\"attributwert2\">");
    I've got a compilation error:
    U:\qms_neu\htdocs\inay\Source\myWork\Regex-Samples>javac Splitter.java
    Splitter.java:14: illegal start of expression
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: illegal character: \92
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: illegal character: \92
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:14: unclosed string literal
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:17: ')' expected
    p.split("<element attributname1=\"attributwert1\" attributname2
    =\"attributwert2\">");
    ^
    Splitter.java:14: unexpected type
    required: variable
    found : value
    Pattern p = Pattern.compile("^<[a-zA-Z0-9_\\"=]+[\\s]*$>");
    ^
    Splitter.java:18: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    for (int i=0; i<result.length; i++)
    ^
    Splitter.java:19: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    if (result.equals("")){
    ^
    Splitter.java:21: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    System.out.println(result[0]);
    ^
    Splitter.java:24: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    System.out.println(result[i]);
    ^
    Splitter.java:25: cannot resolve symbol
    symbol : variable result
    location: class Splitter
    int res = result.length - 1;
    ^
    11 errors

  • Regular expression in java -- specifically email

    Does anyone know how I can do a regular expression with java that is going to retrieve an email address pattern.
    For example, let's say i have a huge string
    this is a sample test. perhaps someoen can tell me how to retrieve my [email protected] from this string. sincerely yours [email protected]
    could someone explain to me how to retrieve these emai addresses most efficiently using java's regular expressions
    thanks
    stev

    A citing (http://jregex.sourceforge.net/examples-email.html):
    String someValidChars="[\\w.\\-]+";
    String someAlphaNums="\\w+";
    String dot="\\.";
    Pattern email=new Pattern(someValidChars + "@" + someValidChars + dot + someAlphaNums);

  • Using regular expressions in java

    Does anyone of you know a good source or a tutorial for using regular expressions in java.
    I just want to look at some examples....
    Thanks

    thanks a lot... i have one more query
    Boundary matchers
    ^      The beginning of a line
    $      The end of a line
    \b      A word boundary
    \B      A non-word boundary
    \A      The beginning of the input
    \G      The end of the previous match
    \Z      The end of the input but for the final terminator, if any
    \z      The end of the input
    if i want to use the $ for comparing with string(text) then how can i use it.
    Eg if it is $120 i got a hit
    but if its other than that if should not hit.

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

  • Oracle Regular Expressions in Java?

    JDEV 10.1.3
    ADF BC
    ADF Faces
    Is there a Java library for dealing with Oracle regular expressions? I would like to be able to test a String against an Oracle regular expression for pattern match.
    Thank you,

    Hi,
    Java supports RegularEpressions: http://www.exampledepot.com/egs/java.util.regex/pkg.html
    Frank

  • "Stupid design of regular expression in java"

    I bet majority will stumble on this:
    String inputStr = "a,,b";
    String patternStr = ",";
    String[] fields = inputStr.split(patternStr);
    result: ["a", "", "c"]
    so if inputStr = ,,
    then result: ["","",""] ??
    If you think so, give yourself a treat.
    Now give yourself a bigger treat. cause
    the result is [""]
    Unbelievable about inconsistency of regular expression.
    It look so irregular.

    Take a look at the site which quote
    http://www.devarticles.com/c/a/Java/Regular-Expressions/10/
    Perl is probably the most popular language to offer regular expression support. As such, it makes sense to put Java&#8217;s regex support in context by comparing it to that of Perl. The distinctions you should be aware of are highlighted in the sections that follow. Generally speaking, J2SE doesn&#8217;t include some Perl constructs, because Java is a full-featured programming language that offers sophisticated condition and logical paths of execution that are reasonable alternatives to the constructs offered by Perl."
    Since, Java doesn't offer means it is perl, why not fix the "weirdness" of perl is in this case ? let the split function work as intended.
    Check this out from Java almanac
    // Parse a comma-separated string
    String inputStr = "a,,b";
    String patternStr = ",";
    String[] fields = inputStr.split(patternStr);
    // ["a", "", "b"]
    // Parse a line whose separator is a comma followed by a space
    inputStr = "a, b, c,d";
    patternStr = ", ";
    fields = inputStr.split(patternStr, -1);
    // ["a", "b", "c,d"]
    // Parse a line with and's and or's
    inputStr = "a, b, and c";
    patternStr = "[, ]+(and|or)*[, ]*";
    fields = inputStr.split(patternStr, -1);
    // ["a", "b", "c"]
    Everything is mentions except to solve the common issue I have.
    http://javaalmanac.com/egs/java.util.regex/ParseLine.html
    The above will failed if any empty data within pipe. It is how you manage to detect the empty data that is relatively important because it screw up your program. And too code to do that increase your chance of program error.
    Sometimes we just accept thing but never question why there aren't better way.

  • Writing Regular Expression with a character ^, too difficult

    I want to change "^1Mandrake ^3Style ^4DM" this sentence to "Mandrake Style DM".
    (^ with number means color code)
    So..I used String.replaceAll() method with regular expression.
    But however hard I try, I cant find any solution for this.
    In php I could use \^ as a ^ character, but java dosnt support \^.
    How can I solve this problem?

    Use \\^ in your regex (you have to escape the slash, too).

  • Problem in creating a Regular Expression with gnu

    Hi All,
    iam trying to create a regular expression using gnu package api..
    gnu.regex.RE;
    i need to validate the browser's(MSIE) userAgent through my regular expression
    userAgent is like :First one ==> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    i wrote an regular expression like this:
    Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)
    Actaully this is validating my userAgent and returns true, my problem is, it is returning true if userAgent is having more words at the end after Windows NT 5.0 like Second One ==> Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) Testing
    i want the regularExpression pattern to validate the First one and return true for it, and has to return false for the Second one..
    my code is:
    import gnu.regexp.*;
    import gnu.regexp.REException;
    public class TestRegexp
    public static boolean getUserAgentDetails(String userAgent)
         boolean isvalid = false;
         RE regexp = new RE("Mozilla.*(.*)\\s*(.*)compatible;\\s*MSIE(.*)\\s*(.*)([0-9]\\.[0-9])(.*);\\s*(.*)Windows(.*)\\s*NT(.*)\\s*5.0(.*)");
         isvalid = regexp.isMatch(userAgent);
         return isvalid;
    public static void main(String a[])
         String userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
         boolean regoutput = getUserAgentDetails(userAgent);
         System.out.println("***** regoutput is ****** " + regoutput);
    }please help me in solving this..
    Thanks in Advance..
    thanx,
    krishna

    Ofcourse, i can do comparision with simple string matching..
    but problem is the userAgent that i want to support is for all the MSIE versions ranging from 5.0 onwards, so there will the version difference of IE like MSIE 6.0..! or MSIE 5.5 some thing like that..
    any ways i will try with StringTokenizer once..!
    seems that will do my work..
    Thanks,
    krishna

  • Can I use regular expressions in Java 1.3

    Hi,
    Dose Java 1.3 suport regular expressions?
    How can I use it?
    Thanks.
    bevin ye

    The 1.3 core API doesn't support regular expressions. Hint: There's an item "Since:" in the JavaDoc of most classes that indicates the version it was initially available. If you look it up in the JavaDoc of java.util.regex.Pattern you'll notice that it's value is 1.4.
    But there are several third party libraries that implement regular expressions, 'though I've not used them extensivly, so I can't tell you which one's the most usefull.

  • Regular Expression in Java problem

    what is wrong with the following regex?
    query = query.replaceAll("SELECT.*?([WHERE.*?|GROUP BY.*?|HAVING.*?|ORDER BY.*?|LIMIT.*?]*?)","\\1");
    when I put in this:
    "SELECT WHERE MlsNumber=\'555555\', AdType=\'MyAdType\'"
    I get this:
    "1 WHERE MlsNumber='5100093', AdType='NytClass'"
    Where is the 1 coming from? I know the backreference must be working or I wouldnt get the WHERE statement back.

    There's a pretty good regex tutorial at this site: http://www.regular-expressions.info/ (I meant to include that in my first reply).
    Basically what I'm trying to do is cut the SELECT and
    anything after it up until it reaches the WHERE (and
    text), GROUPBY, HAVING, ORDER BY, or LIMIT. I want to
    remove The SELECT and text, but keep all instances of
    WHERE text GROUP BY text, etc. I also want to
    keep anything that is past then end of these
    expressions (in case there are option I haven't
    forseen).Try this:  query = query.replaceFirst("SELECT.*?(?=WHERE|GROUP BY|HAVING|ORDER BY|LIMIT)", "");The (?=...) part is a lookahead; it will cause the .*? to stop matching at the first instance of "WHERE", "GROUP BY", "HAVING", "ORDER BY", or "LIMIT". (Check out the "Lookahead & Lookbehind" section in the tutorial for an explanation.) However, if the first thing after the SELECT clause is one of the unknown options you mentioned, it will be removed too. If you know that keywords will always be in all caps, and that none of the other text will be, you could try generalizing the regex like this:  query = query.replaceFirst("SELECT.*? (?=[A-Z]{3,})", "");This regex assumes that any sequence of three or more capital letters preceded by a space is a keyword, which is probably not a safe assumption, but it gives you an idea of the kind of thing you can try.
    I thought the brackets were there to allow you to
    select choices from a group of items, if not I can
    remove them.Alternation doesn't require special bracketing characters. You usually want to enclose it in parentheses, but that's just to isolate it from the rest of the regex (e.g., "abc(?:foo|bar)xyz"). Square brackets are used for character classes, which are a completely different breed of animal; look them up in the tutorial.
    Apparantly the JDK docs are wrong, since they tell you
    to use the \\1 instead of $1 (which works).If you want to use a backreference within the regex, you use \1. For instance, if you want to match a complete HTML element, you might use  String regex = "<(\\w+)[^>]*>.*?</\\1>";But in the replacement string, you use $1. BTW, it's the Matcher docs that tell you that, not the Pattern docs.

  • Perl Regular expression to java Regular Expression

    HI all,
    How can i write java Regular expression for the below Perl Code
    where data.html is my original Html file
    and data2.html is output file.
    open(FPR, "data.html") || die("Could not open data file");
    while ($line=<FPR>) {
    $content .= $line;
    close(FPR);
    open(FPR, ">data2.html") || die("Could not open data2 file");
    # clean white spaces
    $content =~ s/[\n\r\0 ]//g;
    # divide data by td
    $rxp='<tr.*?><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><td.*?>(.*?)<\/.*?td><\/.*?tr>';
    while ($content=~ m/$rxp/g)
    print FPR "\n".$1."\t".$2."\t".$3."\t".$4."\t".$5."\t".$6."\t".$7."\t".$8."\t";
    print FPR "<br>";
    close(FPR);
    can you help in this regard
    Thanks

    I am able to retrive only one row in this format from data.html file
    <trvalign=middlebordercolor=#ffffff><tdwidth='40'CLASS='tdbgpricespagecolorgrey'><fontface='Arial,Helvetica,sans-serif'size='2'>SB</font></td><t
    dwidth="23"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sansserif'size='2'>USAirways</font></td><tdwidth="34"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>MIA</font></td><tdwidth="31"Class=tdbgpri
    cespagecolorgrey><fontface='Arial,Helvetica,sans-erif'size='2'>LGW</font></td><tdwidth="23"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>USAirways</font></td><tdwidth="34"Class=tdbgpricespagecolorgrey><fontface='Arial,Helvetica,sans-serif'size='2'>LGW</font></td>
    But i need the output in this format
    <fontface='Arial,Helvetica,sans-serif'size='2'>SB     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA     <fontface='Arial,Helvetica,sans-serif'size='2'>LGW     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>LGW     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA          <br>
    <fontface='Arial,Helvetica,sans-serif'size='2'>CS     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA     <fontface='Arial,Helvetica,sans-serif'size='2'>LON     <fontface='Arial,Helvetica,sans-serif'size='2'>USAirways     <fontface='Arial,Helvetica,sans-serif'size='2'>LON     <fontface='Arial,Helvetica,sans-serif'size='2'>MIA          <br>
    How can i rewrite the code to achive this.
    Here is my java code
    import java.io.*;
    import java.util.*;
    import java.util.regex.*;
    public class parseHTML {
    public static void main(String[] args)
    try
    BufferedReader in = new BufferedReader(new FileReader("C:\\data.html"));
    PrintWriter out = new PrintWriter(new FileWriter("C:\\data1.html"));
    String aLine = null;
    String abc=null;
    String pattern1 ="<tr.+?><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td><td.+?>(.+?)</.+?td>++";
    Pattern p1 = Pattern.compile(pattern1);
    while((aLine = in.readLine()) != null)
    abc=aLine.replaceAll("(\n|\t|\r)","").replaceAll(" ","");
    Matcher m1 = p1.matcher(abc);
    if(m1.find())
    System.out.println("the value is...."+m1.group());
    out.print(m1.group());
    m1.reset(aLine);
    in.close();
    out.close();
    catch(IOException exception)
    exception.printStackTrace();
    Thanks

  • Using regular expressions in Java SE v1.3.1

    Hi,
    I have made a package in which I use the regular expressions package in J2SE v1.4. Unfortunately it turned out that my users are only using v1.3. I wonder if it is somehow possible to import the regexp package in v1.3?
    Kind regards
    Jesper

    Sorry No you cant use 1.4.1 RE in 1.3.1
    3 ways of getting round this
    1)
    have 2 diff jar Files, one for 1.3.1 and one for 1.4.1
    2)
    use a seperate RE package
    such as the Java RE package (before it was added in 1.4.1)
    or apache's regexp (This is what I do) from
    http://jakarta.apache.org/regexp/index.html
    3)
    tell your users to update to 1.4.1 !!

  • Regular expressions with multi character separator

    I have data like the
    where |`| is the separator for distinguishing two fields of data. I am having trouble writing a regular expression to display the data correctly.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> declare
      2  l_string varchar2 (200) :='123` 456 |`|789 10 here|`||223|`|5434|`}22|`|yes';
      3  v varchar2(40);
      4  begin
      5  v:=regexp_substr(l_string, '[^(|`|)]+', 1, 1);
      6  dbms_output.put_line(v);
      7  v:=regexp_substr(l_string, '[^(|`|)]+', 1, 2);
      8  dbms_output.put_line(v);
      9  v:=regexp_substr(l_string, '[^(|`|)]+', 1, 3);
    10  dbms_output.put_line(v);
    11  v:=regexp_substr(l_string, '[^(|`|)]+', 1, 4);
    12  dbms_output.put_line(v);
    13  v:=regexp_substr(l_string, '[^(|`|)]+', 1, 5);
    14  dbms_output.put_line(v);
    15  end;
    16  /
    123
    456
    789 10 here
    223
    5434I need it to display
    123` 456
    789 10 here
    |223
    5434|`}22
    yesI am not sure how to handle multi character separators in data using reg expressions
    Edited by: Clearance 6`- 8`` on Apr 1, 2011 3:35 PM
    Edited by: Clearance 6`- 8`` on Apr 1, 2011 3:37 PM

    Hi,
    Actually, using non-greedy matching, you can do what you want with regular expressions:
    VARIABLE     l_string     VARCHAR2 (100)
    EXEC  :l_string := '123` 456 |`|789 10 here|`||223|`|5434|`}22|`|yes'
    SELECT     LEVEL
    ,     REPLACE ( REGEXP_SUBSTR ( '|`|' || REPLACE ( :l_string
                                     , '|`|'
                                      , '|`||`|'
                                     ) || '|`|'
                        , '\|`\|.*?\|`\|'
                        , 1
                        , LEVEL
               , '|`|'
               )     AS ITEM
    FROM     dual
    CONNECT BY     LEVEL     <= 7
    ;Output:
    LEVEL ITEM
        1 123` 456
        2 789 10 here
        3 |223
        4 5434|`}22
        5 yes
        6
        7Here's how it works:
    The pattern
    ~.*?~is non-greedy ; it matches the smallest possible string that begins and ends with a '~'. So
    REGEXP_SUBSTR ('~SHALL~I~COMPARE~THEE~', '~.*?~', 1, 1) returns '~SHALL~'. However,
    REGEXP_SUBSTR ('~SHALL~I~COMPARE~THEE~', '~.*?~', 1, 2) returns '~COMPARE~'. Why not '~I~'? Because the '~' between 'SHALL' and 'I' was part of the 1st pattern, so it can't be part of the 2nd pattern. So the first thing we have to do is double the delimiters; that's what the inner REPLACE does. The we add delimiters to the beginning and end of the list. Once we've done prepared the string like that, we can use the non-greedy REGEXP_SUBSTR to bring back the delimited items, with a delimiter at either end. We don't want those delimiters, so the outer REPLACE removes them.
    I'm not sure this is any better than Sri's solution.

  • Regular expressions with dates and multiple matches

    I am currently attempting to automate modifying start and end dates within a .config file via powershell but I am having issues identifying the regular expression for the end date section since both are on the same line in the file. Below is the string that
    I want to change.
    Sometimes the dates are blank and sometimes the dates are filled in.
    Dates are always in the same format (yyyy-MM-dd hh:mm).
    I also want to note that there are multiple instances of 'StartDate="" EndDate=""' for other applications throughout the same config file so I cannot limit the expression to not include the App name. 
    I do not want to limit the search to a line number since there are instances where admins will add an extra space in the config file that may throw off the line number.
    I want to replace the dates or lack there of in their respective spots on the line below via powershell:
     <App name="TestApp" StartDate="2012-03-22 13:30" EndDate="">
    I am successfully able to use 
    $startRegex = '(?<=<App name="TestApp" StartDate=")([^"]*)'
    to replace the StartDate but I can't seem to single out the EndDate with regular expression. What expression can I use to have it ignore what is in the quotations after StartDate and only pay attention to the EndDate value?
    Below is a snippet: 
    $path = d:\inetpub\website\app.config
    $startRegex = '(?<=<App name="TestApp" StartDate=")([^"]*)'
    $starttime = (get-date).ToString("yyyy-MM-dd hh:mm")
    (gc $path) -replace $startregex, $starttime | set-content $path
    I want to accomplish the same for EndDate.
    Thanks in advance!

    If you do this with XML it will be painless and less prone to error.
    $n=$xml.SelectSingleNode('//App[@name="TestApp"]')
    $n.StartDate=$newstartdate
    $n.EndDate=$newenddate
    $xml.Save($filename)
    \_(ツ)_/

Maybe you are looking for