Replacing multiple regexes at once

Hi everybody,
I'm trying to set up a regex replace that functions like this:
String1 replaces String2
String3 replaces String4
and I'm curious, is there a way to set up a single call, like this:
replaceAll( "[String1|String3]", "[String2|String4]" )
where the one call can know which one to replace?
I know it's possible to do:
replaceAll( string1, string2 )
replaceAll( string3, string4 )
but I'm pretty sure I've seen this somewhere. Can anyone give me a hand with the syntax, if it's viable?
Thanks,
Jezzica85

jezzica85 wrote:
Thanks guys,
I guess that means I'll have to try the old standby of one at a time. Hmm, I wonder where I thought I saw that? Maybe I dreamed it... :)
Jezzica85You could do something like this:
public static String multipleReplacements(String text,
        String[] patterns, String[] replacements) {
    // assume patterns.length == replacements.length
    for(int i = 0; i < patterns.length; i++) {
        text = text.replaceAll(patterns, replacements[i]);
return text;

Similar Messages

  • How can I find and replace multiple words at once?

    I need to be able to find and replace words into queens English. For example, I need to replace all instances of "color" with "colour," "tire" with "tyre" etc.
    I'm new to scripting, so simple answers would be appreciated :)

    Hi hobs707,
    Please use the below code for your required output:
    Replace ("color", "colour")
    Replace("tire", "tyre")           
    //Replace("hobs707", "hobs007")     just copy and paste and edit the contents as your wish
    function Replace(input, output)
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.findWhat = input;
    app.changeTextPreferences.changeTo = output;
    app.activeDocument.changeText();
    If the above answer is correct please provide Correct Answers for me.
    Regards
    Beginner

  • Find/Replace - multiple replace ... maybe with regex

    Hello Dreamweaver community ... I'm relatively new to using Dreamweaver as an editor and I'm working on a large migration project that I'm trying to make easier. Basically, I'm converting an entire site from English to Spanish ... almost literally tag by tag
    Something that would make my job a lot easier is if ... every time I open a new Spanish language content file I could ...
    replace ALL Spanish language grammar symbols, accents, tildes etc ... with their HTML equivalents ... for example ...
    á  = &aacute;
    é = &eacute;
    í = &iacute;
    And so on ... there's about 10-12 major changes ...
    What I need to figure out is how to save a find/replace query in Dreamweaver .dwr format that replaces all symbols at once instead of needing to do them one at a time ...
    Seems like this shoudl be possible but I haven't figured out the right syntax ... I used the (.+) and $1 but it only worked conditionally - in the order the replacements were written. I need it to find ALL instances of a spanish symbol and replace it with its corresponding html ...
    Can anyone help me with this ...?
    Thank you in advance ...

    This is in fact the only solution I found to this problem.
    Creating an extension is not that difficult once you have the right
    reference material.
    Have a look at:
    DW API function to find and replace
    http://livedocs.adobe.com/en_US/Dreamweaver/9.0_API/dwr_code_cd_013.html
    Sample extension file on your machine after installing DW
    C:\Program Files\Adobe\Adobe Extension
    Manager\Samples\Dreamweaver\
    Full specifications of the MXI (extension file) format
    http://download.macromedia.com/pub/exchange/mxi_file_format.pdf
    quote:
    Originally posted by:
    Newsgroup User
    > So, is it indeed possible to run more than one
    find/replace query at a
    > time?
    As far as i know, no it's not possible.
    There has been mentions in the past to this question that a
    series of
    find/replace queries could be built as a dw extension instead
    of a saved
    search query.
    Alan
    Adobe Community Expert, dreamweaver

  • Is there a way to format multiple images at once? Change colour mode or resolution?

    Is there a way to format multiple images at once? Change colour mode or resolution?

    It's very easy to make an action.
    Go to window > actions
    In the actions panel, simply click the 'create a new action' button, it starts recording as soon as you've created it (when you've given it a name).
    Now you can apply the changes you want to make to the images on the file you have opened.
    After you've done all you need to do. You click the 'stop' button. The action is now ready to use. And you can apply the changes you made on all the other files.
    Then you can continue how gener7 explained.
    I usually include a save and close command, so that the whole batch doesn't end up opened after running the script.
    But if you do that you have to create a new file, and save it to your computer before you start recording the action, otherwise the save command will be replaced by each file. And you'll end up with one edited file in the end. At least for as far as I know!

  • ANN: Tutorial on Replacing Multiple or Single Templates in DW on   Child Pages

    FYI: this article is available for free reprints, as long as
    guidelines are
    followed:
    http://www.petersonsales.net/tutorial1.php
    Replacing Old Website Templates in Dreamweaver
    One of the most difficult tasks for a web designer is
    updating legacy
    websites. Legacy websites are websites which have existed for
    many years.
    Often these sites have outdated code or are badly in need of
    an upgrade. For
    years, Dreamweaver has used templates to allow an entire site
    to be updated
    at once simply by making changes to a master page. But what
    do you do when
    the template itself was developed with outdated code and the
    site needs a
    complete design overhaul? How do you fix it without having to
    cut and paste
    the content from every existing page to a newly designed one?
    Part 1 - Overwriting a Single Template
    Part 2 - Replacing Multiple Templates with One
    ~~~~~~~~~~~~
    Jefferis Peterson, Pres.
    Web Design and Marketing
    http://www.PetersonSales.com

    What Ken has said also applied to
    <img src="/assets/images/Lights/lights_select.jpg" width="400" height="400" alt="Lighting Thumbnails" />
    which look for the JPG in http://davidcoshdesign.com/assets/images/Lights/lights_select.jpg rather than http://davidcoshdesign.com/nea/assets/images/Lights/lights_select.jpg
    Gramps

  • How do I delete multiple items at once instead of one at a time?

    How do I delete multiple items at once instead of one at a time? I have several duplicate items in my library and would like to delete the duplicates. Thanks!

    You can select multiple items using shift to select a range and control to add or remove items from it.
    Regarding duplciates, Apple's official advice is here... HT2905 - How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
    Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group of identical tracks to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created.  If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin. This can happen, for example, if you start iTunes with a disconnected external drive, then connect it, reimport from your media folder, then restart iTunes.
    Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background. Please take note of the warning to backup your library before deduping, whether you do so by hand or using my script, in case something goes wrong.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    tt2

  • How can I delete multiple photos at once from the official Photos app?

    Dear fellow Apple users,
    I have many pictures on my Camera Roll in Apple's Photos app. What's the quickest way to delete multiple photos at once?
    Thus far, I know how to delete photos one by one, but that's time-consuming.
    Thank you.

    No not box with arrow, that is share button.  Edit is where it shows in the pic I posted

  • From my music how do i move multiple songs at once to a playlist

    From( My Music) how do I move multiple songs at once to a playlist.
                                        Thanks

    Your issue has nothing to do with Apple networking. You may get better results in getting a solution if your post your issue to the iTunes area of the Apple Support Communities.

  • How to replace multiple occurences of space in a string to a single space?

    How to replace multiple occurences of space in a string to a single space?

    Hi,
    try this code.
    data : string1(50) type c,
              flag(1) type c,
              dummy(50) type c,
              i type i,
              len type i.
    string1 = 'HI  READ    THIS'.
    len = strlen( string1 ).
    do len times.
    if string1+i(1) = ' '.
    flag = 'X'.
    else.
    if flag = 'X'.
    concatenate dummy string1+i(1) into dummy separated by space.
    clear flag.
    else.
    concatenate dummy string1+i(1) into dummy.
    endif.
    endif.
    i = i + 1.
    enddo.
    write : / string1.
    write : / dummy.

  • Replace multiple space characters with a single space

    Hi,
    Oracle 11g R2.
    Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
    select replace(column1, chr(32)||chr(32), chr(32)) from tablea

    Hi,
    If you had to do this without regular expressions, you could use:
    SELECT  REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
                     , ' ~'
              , '~ '
              )     AS new_str
    FROM    table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
    However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler.

  • Replacing multiple spaces with a single space

    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!

    Hi,
    964559 wrote:
    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'One solution is to post your string on this site, and then copy it back again. (See below for a more serious solution .)
    This site is doing exactly what you want the function to do: it replaces multiple consecutive spaces with a single space. As a result, it's hard to see what you mean.
    To preserve spacing on this site, type these 6 characters
    \(small letters only, inside curly brackets) before and after each section where you want spacing preserved.
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!Regular expressions make this easy:SELECT TRIM ( REGEXP_REPLACE ( str
    , ' +'
    ) AS compressed_str
    FROM table_x;
    You can use nested REPLACE calls to get the same results, but it's messy.
    Edited by: Frank Kulash on Feb 5, 2013 10:18 AM
    Added TRIM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • ICloud keeps duplicating my contacts, any of which I need to delete anyways.  Is there a way to delete multiple contacts at once? I  have been deleting them one at a time, but they keep reappearing.

    ICloud keeps duplicating my contacts, any of which I need to delete anyways.  Is there a way to delete multiple contacts at once? I  have been deleting them one at a time, but they keep reappearing.

    I have exactly the same problem!  I have Outlook 2010 and it does the same thing with my contacts, and calender enteries!! Really frustrating

  • Insert data into multiple entities at once using a view object

    Hi,
    I'm trying to insert data into multiple entities at once using a view object, but unfortunately it doesn't seem to work. The two entities have a 1:1 association. I created a view object which contains both entities and I made sure they aren't read-only. But like I said it doesn't work, I can't insert data in both entities at once... :(
    Is this possible? And how (if it is)?

    Hi,
    I'm trying to insert data into multiple entities at once using a view object, but unfortunately it doesn't seem to work. The two entities have a 1:1 association. I created a view object which contains both entities and I made sure they aren't read-only. But like I said it doesn't work, I can't insert data in both entities at once... :(
    Is this possible? And how (if it is)? Peter:
    This is definitely supported and tested. Please send us the exception stack trace. You must running into other problems. A few things to note:
    A) You have to mark the entities as both updateable (not read-only) and not reference-only.
    B) If you're not seeing an exception stack, turn on diagnostic. Here is how:
    To turn on diagnostic, go to the IDE,
    1. Select the project.
    2. Do right mouse click and select "Project Settings..."
    3. On the Settings dialog, select Configurations/Runner.
    4. In the righthand side pane, you should see a textbox for "Java
    Options". Please add the following JVM switch:
    -Djbo.debugoutput=console
    Then, rerun. The run command should include
    -Djbo.debugoutput=console as in
    "D:\JDev9i\jdk\bin\javaw.exe" -Djbo.debugoutput=console -classpath ...
    You should now see a lot more output on the IDE's message window. Here you should see the exception stack trace.
    If you invoking your app directly from command prompt, just add "-Djbo.debugoutput=console" after your "java.exe".
    Thanks.
    Sung

  • How to find and replace multiple cells at a time

    I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
    i.e. doing my own budget spreadsheet and coding all transactions with description and code

    Did you try the "Find/Replace" dialog box?:
    Then click the "Replace All" button in the bottom left.

  • How do I apply a preset to multiple images at once?

    I'm almost embarassed to ask this, because it seems so simple. But I'm new to LR and need some help.
    I want to apply a preset (exmample, a preset that resembles film) to multiple images at once. (similar to batch editing in Photoshop) but I want want the white balance etc to necessarily be the same, obviously. Please help!

    Select all of your thumbnails in the develop module film strip or in the library prior to going into develop. Then turn on Auto-Sync. Any adjustment you make to your first image will be repeated on all of the selected images. Or just perfect your first image and choose sync. You will see a pop-up dialog and you can choose exactly which develop settings you wish to sync e.g. white balance only or white balance and other settings.
    To be clear Auto-sync will apply all develop settings on the fly to all selected images.
    Sync will apply the settings from the first selected image to all of the subsequently selected images unless you choose exceptions. For example you may wish to apply exposure, contrast, highlights and shadows from your perfected image but not the crop settings.
    Don't forget to turn off Auto-Sync when you have finished otherwise it will affect future editing.
    P.S. There is no such thing as an embarrassing question. The beginners forum is designed entirely for that purpose.

Maybe you are looking for

  • Can I Copy CS3 Apps from One Mac to Another and Make them Work?

    First off, I KNOW how this sounds at first blush. I am NOT trying to violate the EULA. I have legitimate serials for Creative Suite 3. HOWEVER I'm in a position where my new Mac will not allow me to install CS3 from the disks or DMGs made from them.

  • IMovie still too big

    I thought I had solved my problem by splitting the movie in part 1 and part 2. I took the first part (after I cleared the rest of the movie) and tried to SHARE it with iDVD, But I still get the message that it is too long for a DVD. This first part i

  • Complete Newbie - just need a kick start with advice

    Hi to the Forum - I'll try to be brief and hope someone can answer a few queries to save me some time. I want to develop a web based system, SQL backend, browser front end and also have a mobile APP that will run on all smartphones. I am competent in

  • MSS and Positions

    Positions in SAP can be 100% filled, partially filled or vacant.  One position may also be shared by several employees, each working less than full time. For example, two employees can hold 60% and 40% of one position. So why is it recommend in MSS t

  • Scripting variable

    Is there a any chance to make scripting variable act lika a managed bean? If I define my bean as scripting variable, not managed bean and when page is loaded, bean isn't initialized. <h:inputText styleClass="inputText" id="postnumber" value="#{bean.p