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

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

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

Similar Messages

  • Back reference for regular expressions on "Search & Replace".

    Can't I reference a result from my Regular Expression used on "Search Clause" into my "Replace Clause"?
    What I'm doing is:
    Using JDev 10.1.3 DP,
    Search Menu -> Replace in Files...
    Select "Regular Expressions"
    Text: (A[0-9]*?_)(.)
    Replace with: $2 (reference to the second Parenthesis in the "Text" Field).
    For example, in Java, I would so something like this:
    "Dummy String".replaceAll("(D.*? )(S)", "$2");
    Are there any other ways that I can just Search something and Replace for nothing? I need a simple "Search and Delete", you know?
    If I don't do that and try to leave it blank, a warning comes up saying that the "Replace with" field cannot be blank.
    Any sugestions?

    BOUNCE!
    Please, anyone?
    Will I really have to delete 1200 occurrences by hand???
    :(

  • Regular expressions for replacing text with sms language text

    Hi, I'm trying to write a function which converts normal, correctly spelled text into the shorter sms language format but struggling to come up with the regular expressions i need to do so, can anyone help?
    1: remove surplus white space at the beginning of a sentence and at the end of a sentence.
    e.g. " hello." --> "hello." OR "hello ." --> "hello."
    2: remove preceeding and/or proceeding space if there's a word then a number possibly followed by another word
    e.g. "come 2 me" --> "come2me" OR "dnt 4get" --> "dnt4get"
    3: remove "aeiou" if word starts and ends with "!aeiou"
    e.g. "text" --> "txt"

    You can make the whitespace on either side optional:   text = text.replaceAll("\\s*(\\d)\\s*", "$1");1. Use String's trim() method.
    3. This one has to be done in two steps: import java.util.regex.*;
    public class Test
      public static void main(String... args) throws Exception
        String text = "The quick brown fox jumps over the lazy dog.";
        System.out.println(devowelize(text));
      public static String devowelize(String str)
        Pattern p = Pattern.compile(
          "[a-z&&[^aeiou]]++(?:[aeiou]++[a-z&&[^aeiou]]++)+",
          Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
          m.appendReplacement(sb, m.group().replaceAll("[aeiou]+", ""));
        m.appendTail(sb);
        return sb.toString();
    }

  • Regular expression to replace "emtpy space" ( ) bitween words with +

    Hallo!
    When I wish to find in code something like this:
    12144541 FirstWord SecondWord
    regular expression for that is:
    (\d{1,100})[\s-]\D{1,100}[\s-]\D{1,100}
    Now, please help me tu find regular expression to replace
    "emtpy space" ( ) bitween words with +
    12144541 FirstWord SecondWord to become
    12144541+FirstWord+SecondWord
    Thank you very, very, very much!

    A simple-minded solution is to use \s to match all
    whitespace; e.g. find \s and replace with +. DW CS3, at least, is
    smart enough to not replace end of line characters with the '+'
    character if you limit your search & replace to text.

  • Looping through files with Regular expressions ?

    Hi,
    My Question is:
    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?
    [ e.g. to check for something like, if the captured group has a 1 followed by a 3
    followed by a 5 followed by a and so on ].
    Thanks Very much for any help, i've been struggling with this for a while!!
    Much appreciated
    The code that i have so far is as follows:
    import java.util.*;
    import java.util.regex.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.*;
    public class ExpressReg {
    public String Edit;
    public ExpressReg(String editorEx){
    Edit = editorEx; // Edit = JTextArea
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    //String regrex1 = "(.*;)";
    Pattern p = Pattern.compile(regrex);
    Matcher m = p.matcher(editorEx); // matcher can have more than one argument!
    boolean result = m.find();
    if(result){                           
    JOptionPane.showMessageDialog(null, "String Present in Editor");
    else if(!result){
    JOptionPane.showMessageDialog(null, "String Not Present In Editor");

    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?Yes, the capturing group is $1 (the only one) referenced in source code as m.group(1).
    m.group() will return entire matching.
    simply use this way:
    String result = m.group(1);
    // your stuff: could be another validation
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?Again "Yes", no limits!
    Don't need to create another Matcher, just use m.reset(anotherSourceString)..loop using the same pattern.
    Note: Take care with ".*" because regex nature is "greedy", be more specific, eg.: "\\d" just matches digits (0-9).
    Can you give us some sample of "slight difference" ?

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • How to search with regular expression

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

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

  • Esing regular expression to reformat text (match & replace)

    Hi guys ..I am using regilar expression to reformat logs files..
    this is how i match the pattern..
    Pattern pattern = Pattern.compile("^<[^>]*>(.{6}).....
    Matcher matcher = pattern.matcher(thisLine);
    then prints the output...
    myOutput.print(matcher.group(1));
    It works..however my prob now is, i am reading a date in format "8 Nov"
    How can i change this to 8-11-2005 ????

    hmmm....ya..i can see the idea
    (\\d\\d?) (Jan|Feb|Mar|Apr|May|Ju[nl]|Aug|Sep|Oct|Nov|Dec) means that the month can be either one rite?
    but the thing is..its collected and put in a group. for example:
    Pattern pattern = Pattern.compile("^<[^>]*>(.{6}) ...
    myOutput.print(matcher.group(1));
    the first regular expression is group in group(1). its working..it can detect the text in group(1) the problem was...i tried this..
    String priority = matcher.group(6);
                   if (priority=="3")
                        System.out.print("AAA\n");
                   else
                   System.out.print("BBB\n");
    it keeps on printing BBB even there is a "priority=3".

  • Assistance with Regular Expression and Tcl

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

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

  • Problem with Regular Expression

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

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

  • Get the string between li tags, with regular expression

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

    No one?
    Anoyone here experienced with Regular Expression?

  • Matching Quotes With Regular Expressions

    Hi, I have been attempting to develop an app which extract texts from pdfs then applies regular expression to the text. In one instance I attempt to match a curly open quote symbol which matches the . construct as well as the \W. However, it does not match \p{Punct} or \p{P} - does anyone know why this might be?
    I have read that a pattern \p{Pi} exists for matching opening brackets but am told when I run Java that no such characters class exists - is there anywhere where I can get info on all of the character classes available (not the Pattern javadoc)?
    Thanks very much,
    Ross

    . construct match anything and \W matches any non alphanumaric
    to match a curly bracket use \{
    Basicaly ( { [  has special meanings in regex so when you match them you have to use \{, \(,  \[  in java strings it means \\{, \\(, \\[                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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)');

  • Need a regular expression for the text field

    Hi ,
    I need a regular expression for a text filed.
    if the value is alphanumeric then min 3 char shud be there
    and if the value is numeric then no limit of chars in that field.[0-9].
    Any help is appriciated...
    thanks
    bharathi.

    Try the following in the change event:
    r=/^[a-z]{1,3}$|^\d+$/i;
    if (!r.test(xfa.event.newText))
    xfa.event.change="";
    Kyle

  • Replace All with Regular Expression

    Hi all,
    I need a help to replace the String:
    to
    "<a href=\"1\"">Java Programming</a>"
    I was trying to replace with
    .replaceAll("\\[\\[*([^\\]]*?)*\\]\\]", "<a href=\"\"></a>")
    but I don't know how to separate the parameters values.
    Best regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi prometheuzz,
    you are the one!!
    But how I could do to a Srting like this:
    Ah, more requirements...
    Things are getting a bit messy now:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    class Main { 
        public static void main(String[] args) {
            String line = "any text any text any text any text any text. "+
                          "Click - [[Code: 6 Title: Java Programming]]. "+
                          "any text any text any text any text any text. "+
                          "- [[C�digo: 2 T�tulo: Sun]] text text "+
                          "any text any text any text any text any text.";
            String newLine = line;
            String[] wikiTags = getWikiTags(newLine);
            for(String tag : wikiTags) {
                String newTag = "<a href=\""+get("(Code:|C�digo:)", " ", tag)+
                                "\">"+get("(Title:|T�tulo:)", "$", tag)+"</a>";
                newLine = newLine.replaceFirst("\\[\\["+tag+"\\]\\]", newTag);
            System.out.println(line);
            System.out.println(newLine);
        public static String[] getWikiTags(String text) {
            java.util.List<String> list = new java.util.ArrayList<String>();
            Pattern pattern = Pattern.compile("(?<=\\[\\[)(.*?)(?=\\]\\])");
            Matcher matcher = pattern.matcher(text);
            while(matcher.find()) {
                list.add(matcher.group());
            return list.toArray(new String[list.size()]);
        public static String get(String start, String end, String text) {
            Pattern pattern = Pattern.compile("(?<="+start+"\\s)(.*?)(?="+end+")");
            Matcher matcher = pattern.matcher(text);
            return matcher.find() ? matcher.group() : "#ERROR#";
    }Details about regex:
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
    http://www.regular-expressions.info/java.html
    http://java.sun.com/docs/books/tutorial/essential/regex/
    >
    Thanks a lot for you helpLike I said, it's a bit of a messy solution. See if you can use (a part of) it.
    Good luck.

Maybe you are looking for