Replace exact string only

I'm outputting text content to my page by querying our
database using a simple method, which works fine.
quote:
<cfoutput query="getPageContent" startrow="#vPageContent#"
maxrows="1">#vContent#</cfoutput>
I need to replace certain words to make them bold, for
example...
quote:
<cfset request.vContent = replace(request.vContent,
"phrase", "<B>phrase</B>, "ALL")>
This works, but there is a slight issue, because it will also
replace occurances of the word 'phrase' even if it is within
another word...
for example, co
phrasetastic
So i need to replace only the exact phrase when used on it's
own.
My problem appears quite simple, but I have not found a way
to do this...?

quote:
Originally posted by:
Newsgroup User
Sam_Ham wrote:
> <cfset request.vContent = replace(request.vContent,
"phrase", "
phrase,
> "ALL")>
note the spaces in the following:
<cfset request.vContent=replace(request.vContent," phrase
phrase
","ALL")>
or use regex via the reReplace method with something like the
"transition
boundary" escape sequence "\b" (check the syntax, doing this
from poor memory):
reReplace(vContent,"\bphrase\b","
phrase","ALL")
Thanks Paul... it works like a charm!

Similar Messages

  • Replace exact string from a list seperated by ":" delimeiter

    Hi,
    How can I replace PROJ1 with PROJ4 and cover all the following options, when items are seperated by ":" delimiter.
    1)     PROJECT_NAME=PROJ1
    2)     PROJECT_NAME=PROJ1:PROJ2
    3)     PROJECT_NAME=PROJ2:PROJ1
    4)     PROJECT_NAME=PROJ1:PROJ11
    5)     PROJECT_NAME=PROJ3:PROJ1:PROJ2
    in case #4 i want to save PROJ11 and to replace only PROJ1
    Thanks,
    Sheli

    Hi, Etbin,
    Sorry, I can't figure out what you're asking.
    Etbin wrote:
    Not wanting to write regular expressions without database checkingAre you asking if this can be done without regular expressions? Yes, but it's not pretty. It would involve several layers of nested REPLACE (and/or other string manipulation) functions, even without worrying about multiple consecutive occurrences of the target string.
    I wonder whether in replacing PROJ1 with PROJ4 we could request to replace PROJ1 only as a complete word ?The solutions above already replace 'PROJ1' only when it is a complete word, not when it is a sub-string of a larger word such as 'PROJ11' or 'SUBPROJ1'.
    In this problem, I'm thinking of a "word" as being something delimited by '=', ':' or end-of-string. Does your question involve some different meaning of "word"?
    PROJ11 seems to represent the only threat to obtain the wrong PROJ41'PROJ11' is the only example in the given sample data, where the word starts with the target, but then continues. Both solutions above would also handle cases where a word ends with the target, but has something extra first (such as 'SUBPROJ1') or where there are extra characters both before and after the target (e.g. 'SUBPROJ11').
    or I'm (lately much too often) missing somethingI'm definitely missing something: a clear idea of what your question is.
    Maybe you're just trying to get me to use my funny name for this problem" "I found love in Slovenia". If so, thank you. I'm always happy to have such an oppoortunity.

  • Exact string search

    i was wondering if there was a way to do an exact string search in a document.
    If i have a document that has punctuation i want to be able to find the document only if i query whith an exact string match, including stopwords and punctuations.
    if the query is
    select *
    from documents1
    where contains(OBJECT_VALUE,'{hello, world}') > 0
    I want only to return the documents that have exactly "hello, world" whith the comma included.
    If i add the comma to printjoins, it would work, But when i query for only "hello" it wont match "hello, world"
    basicaly im looking for something that does a normal search but then check if the exact string is in the match area.

    Try this
    select substr(&P, (INSTR(&P, CHR('32'), 1))+1, (INSTR(&P, CHR('32'), 1)))
    from dual
    &p is a variable
    I am sure this will help you in any of case
    chr(32) will return space, If you have any other thing except space then you just replace 32 with that ascii code. Such as for
    1(we)2 then query will be
    select substr(&P, (INSTR(&P, CHR('40'), 1))+1, (INSTR(&P, CHR('41'), 1)))
    from dual
    Try it and tell is it working fine

  • How can I search for an exact string match in my emails?

    I was looking for an old email that I had about Re-Animator The Musical. So, in the search bar in the upper right corner of the Thunderbird window, I typed "re-animator". I got 59 hits, and the message that actually contained the string "re-animator" was 27th, when sorted by relevance. All of the other hits were emails which contained the word "animal" or "animals", which to me has nothing to do with "re-animator". I'm surprised that those were considered hits at all, much less that they were considered more relevant than the one message which actually contained the desired string.
    I actually tried three different searches:
    reanimator
    re-animator
    "re-animator"
    (i. e. the first two were without quotes and the third was with quotes). All three of these variations had the same problem, though, that messages containing "animal" were ranked before the message containing "re-animator".
    The desired message contained the word "Re-Animator" (with that capitalization and hyphenation), and also contained "reanimatorthemusical" as part of a URL that was mentioned in the message. So, I would have expected both the search with the hyphen and the search without the hyphen to have been good hits for this message.
    My question is: How can I tell Thunderbird to search for messages that literally contain the string I ask for, and not get "creative" with the matches, as it seems to be doing for some reason?
    (I'm using Thunderbird 31.3.0 on Mac OS X 10.9.5.)

    No, searching for:
    "Animator" musical
    still has the exact same problem: it still wants to find "animal" instead of "animator". Why?
    Yes, I had already read the support article you linked to, but I hadn't found anything in it about why Thunderbird would prefer "animal" over "animator", or how to disable this misfeature. Is there no better documentation for the search bar than that?
    (And the search for "Animator The Musical" didn't find my message, simply because my message didn't contain that exact string. It contained "I am on a waiting list for some musical tickets for Sunday, but I haven't heard back yet. It is a preview of The Re-Animator. ( http://www.reanimatorthemusical.com/ )." The search for "Animator The Musical" only had a single hit, your message in which you suggest searching for that.)

  • Problem in replacing the String in a Fille.

    I need to replace the String in the text file, am able to do it partially.
    I mean, am able to replace it. But there are some discrepancies if the replacement string is of "less" or "more" in length than the existing one.
    I solved it for the replacement string of less size, but am unable to do it for the string of more size.. :(
    The problem am facing is "when the replacement string is larger than the existing one, then the other subsequent line in the file gets overwritten".
    I have used RandomAccessFile class for reading and writing the same file.
    fpointer1 = randomFile.getFilePointer() - strLine.length() - 2;
    strLine1 = strLine;
    int sInd = strLine1.indexOf('\'');
    int eInd = strLine1.indexOf(';');
    String oldStr = strLine1.substring(sInd + 1, eInd - 1);
    strLine1 = StringUtils.replace(strLine1, oldStr, newStr);
    if (oldStr.length() < newStr.length()) {
    int diff = (newStr.length() - oldStr.length()) + 1;
    randomFile.writeBytes("\r\n");
    for (int i = 0; i < diff; i++) {
    randomFile.writeBytes(" ");
    randomFile.seek(fpointer1);
    randomFile.writeBytes(strLine1);
    } else if (oldStr.length() > newStr.length()) {
    randomFile.seek(fpointer1);
    randomFile.writeBytes(strLine1);
    int diff = (oldStr.length() - newStr.length()) + 1;
    for (int i = 0; i < diff - 1; i++) {
    randomFile.writeBytes(" ");
    randomFile.writeBytes("\r\n");
    break;
    }Can u pls help me in resolving this issue???...

    boopathi wrote:
    As u said the overwriting causes the problem, but i managed to resolve for the string of less size.I assume you did this with some padding? That's not exactly a clean solution.
    So thats why am seeking to manage the larger size string to replace without overwriting the sub sequent lines.
    Can you help me in suggesting whether it can be resolved using the getFilePointer() and seek() methods??...No you can't.
    Whether you shorten or lengthen the position where you modify the file, you need to move the remaining bytes back or forward, depending which is the case.
    You managed to solve the first case by printing out padding, so you don't need to move the bytes back, but you can't solve the other case like this. You can lengthen the file and move the remaining bytes forward, but I probably wouldn't bother since a simple Reader-based approach is a lot better and easier to get right.

  • Replacing a string of character by another one with emacs

    Hello,
    With Vim, I had something like this in my setup (tex.vim in ftplugin)
    imap <buffer> ... \ldots
    imap <buffer> « \og
    imap <buffer> » \fg
    imap <buffer> " \textquotedblleft
    imap <buffer> ¢ \textquotedblright\
    imap <buffer> € \EUR
    imap <buffer>~ $\sim\
    imap <buffer> // \\
    imap <buffer> /np \newpage
    Currently, I am trying emacs, and would like the same setup. I have searched the web, but with no luck. Indeed, I've just found the following code (and made some modifications to try it) :
    (defun replace-string-pairs-region (start end mylist)
    "Replace string pairs in region."
    (save-restriction
    (narrow-to-region start end)
    (mapc
    (lambda (arg)
    (goto-char (point-min))
    (while (search-forward (car arg) nil t) (replace-match (cadr arg)) )
    ) mylist
    (defun replace-chars (start end)
    "Replace "..." by "\ldots" and other similar chars"
    (interactive "r")
    (replace-string-pairs-region start end '(
    ("..." "\ldots")
    ;("<" "&lt;")
    ;(">" "&gt;")
    But it doesn't work.
    Does anyone know how could I replace "..." by "\ldots" and other things like that with Emacs ?
    Last edited by alexandre (2010-09-28 17:48:50)

    Thank you a lot for your answer, but my problem was not to replace "..." by "\ldots" after typing it, but how could I replace "..." by "\ldots" while I am typing it, just after I finished to push the last dot.
    I have tried to set it up with the abbrev mode, but it seems to work only for words. So for example, if I enter the word such as, say, "arch", then it replace it automatically by "archlinux" after pressing the space key. I won't have to replace the string manually, it does it automatically with the abbreviation mode of Emacs. Here is an example of what I am talking about :
    (abbrev-mode t) ; completion automatique
    (global-set-key (quote [tab]) (quote dabbrev-expand))
    (setq default-abbrev-mode t)
    (define-abbrev-table 'global-abbrev-table '(
    ("..." "\ldots" t)
    ("arch" "archlinux" nil)
    But my problem is, it doesn't work for "...", just for words. Of course, I could do it manually with the shortcut you wrote, but it would be nice to make it work automatically. Is there a way to do so ?
    If you don't understand what I am talking  about, try Vim, copy "imap <buffer> ... \ldots" in your .vimrc, and Vim will replace all "..." by "\ldots" while typing. I am sure I can do it with Emacs, I just don't know how.
    Last edited by alexandre (2010-09-30 12:28:38)

  • Forcing an exact string match in searches

    Is there a way of using the Case Exact String and Case Ignore String plugins so I can ensure that the iPlanet directory server only returns exact matches to an LDAP client.
    e.g.the difference in
    ldapsearch "cn=Abc"
    ldapsearch "cn=ABC"
    I want to find only "ABC" and NOT Abc or abc or aBc and so on..

    You can accomplish this using extensible matching rules.
    By default, the cn attribute is not case-sensitive. You can search for a case-sensitive cn value with a search filter like:
    cn:2.5.3.15:=ABC
    This will use the 2.5.3.15 (Case Exact Match) matching rule on the cn attribute. Note that this search will not be indexed, however, and will take longer than a normal cn search for an exact value.
    You can find more information on extensible matching in RFC 2254 (http://www.ietf.org/rfc/rfc2254.txt).

  • FQL query text to search for exact string

    Hi
    we are using SharePoint 2010 with FAST search...
    I'd like to be able to search for this exact string that contains parentheses...  "(ABC)"
    I thought it would be:
    ManagedProperyName:"(ABC)"
    this returns results with just ABC ... it ignores the parentheses... i need to only show documents with "(ABC)"

    For exact query you can use  equals. For example MPName:equals("<term or phrase>")
    However, in your case the parenthesis is considered a special characters which are stripped off during document processing and at query time.

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Replace a String pattern

    I have the following string:
    String="TVBeginEsternTVEnd
    MovieBeginN/AMovieEnd
    TVBeginPacificTVEnd
    MovieBeginN/AMovieEnd......................"
    I need to replace only the contents between TVBegin and TVEnd. The result (If I want the content=Midwest) should look as follow:
    String="TVBeginMidwestTVEnd
    MovieBeginN/AMovieEnd
    TVBeginMidwestTVEnd
    MovieBeginN/AMovieEnd......................"
    Do you have any suggestions on how to replace the string content?
    Thank you very much!

    Sheshy,
    We can tell you how to do small things, one at a time, all day long. You really need to learn how to read the documentation. Go read the documentation for String, StringBuffer. You can figure it out. Really.

  • Stringbuilder  replacement of string ?

    can we say stringbuilder is replacement of string class. Because stringbuilder provides all features of string with mutability advatange. i mean whereever we used string in past we can simply use stringbuilder in plase of that ?

    JavaFunda wrote:
    Yes i agree its a programming error if we dont declare source variables as synchronized . But i am trying to understand if we dont declare source variables(say one is string and another is strinbuilder) as synchronized, how come string immutability provides the advantage over string builder mutability in? Thats the only intention of question. sorry for inconvenience.First, you can't declare variables as synchronized; you can only declare them as 'volatile', which is slightly different.
    The advantage of an immutable object, be it String or any other type, is that you know it can't change. That means that you can hand it around in a multi-threaded environment secure in the knowledge that Thread B will see the same value as Thread A. If you hand around a StringBuilder, you have no such guarantee because any third party that has access to the same object can change it.
    There is also a category of objects called "Thread-safe", but it's too big a topic to go into here. I suggest you read up on the subject in the tutorials or via Google. I'll just say this: immutable objects are Thread-safe by definition.
    Other than the exception I listed above, the only real advantage of a StringBuilder is that you can sometimes build String-like values faster and more concisely with it than you can with String (and in most cases we're talking nanoseconds of difference). If you're dealing with very large iterations, it may make a difference (particularly in space), and it's also more likely that code that uses StringBuilder will run in more constant time; but you still have the overhead of having to convert back to Strings at some point, because far more methods take Strings than StringBuilders.
    Winston

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • How to search and replace a string in Excel Shape (textbox) using Powershell.

    I have been asked to write a PS script to search/replace a string when found in Excel Shapes when they are textboxes. I have seen lots of simplistic PS scripts and even I can do a "foreach" loop through all the Shapes on a Sheet and display the
    Name of each Shape. But I have not found a property or method to expose the actual text in a textbox let alone change it.
    I have seen vba script that does this as:  
    Set xWs = Application.ActiveWorkbook.Worksheets(I)
    For Each shp In xWs.Shapes
    xValue = shp.TextFrame.Characters.Text
    shp.TextFrame.Characters.Text = VBA.Replace(xValue, xFindStr, xReplace, 1)
    Next
    In Powershell, shp.TextFrame.Characters.Text is ignored and returns nothing.  It would be nice to know if this is possible in PS and if so, know how to do it and/or get an example to work from.  I would have thought that
    PS and VB would use the same Excel object model but apparently they do not.
    I am using Excel 14.0 and PS 3.
    Any suggestions would be appreciated,
    Michael

    This didn't work for me.  I have the shape object and it shows the textframe property:
    PS C:\> $shape | gm
       TypeName: System.__ComObject#{00024439-0000-0000-c000-000000000046}
    Name                       MemberType Definition
    Apply                      Method     void Apply ()
    CanvasCropBottom           Method     void CanvasCropBottom (float)
    SoftEdge                   Property   SoftEdgeFormat SoftEdge () {get}
    TextEffect                 Property   TextEffectFormat TextEffect () {get}
    TextFrame                  Property   TextFrame TextFrame () {get}
    TextFrame2                 Property   TextFrame2 TextFrame2 () {get}
    ThreeD                     Property   ThreeDFormat ThreeD () {get}
    But trying to access it gives an error:
    PS C:\> $shape.textframe | gm
    gm : You must specify an object for the Get-Member cmdlet.
    At line:1 char:20
    + $shape.textframe | gm
    +                    ~~
        + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
        + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
    PS C:\> $shape.TextFrame.Characters().text="hello"
    You cannot call a method on a null-valued expression.
    At line:1 char:1
    + $shape.TextFrame.Characters().text="hello"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    I hope this post has helped!

  • Batch File Search and Replace a String

    I've written a batch file to handle the copying of files.  I'm trying to reduce the number of parameters that I pass to the batch file.
    I want the batch file to perform a string replace on the directory path that is passed as a parameter to the batch file.
    Here is how I run the batch file:
    COPY_FILE.BAT C:\DATA\FTP_DATA\ACME\IN      (I'm passing directory path "C:\DATA\FTP_DATA\ACME\IN" as parameter %1)
    So my batch file will copy a file to the directory path represented by parameter %1.
    But then I want the file copied to a second directory.  I want the batch file to replace string "FTP_DATA" in the directory path with string "FTP_DATA\ARCHIVE"
    I know I could pass this path as a second parameter, but I want to limit the number of parameters so figured I could have the batch file perform a search and replace on string "FTP_DATA".
    After searching the internet, I thought I found the answer by using the following command in the batch file:
    set ARCHIVE_PATH=%1:FTP_DATA=FTP_DATA\ARCHIVE
    But it doesn't perform a search and replace.  It just appends to the directory path with the following result:
    C:\DATA\FTP_DATA\ACME\IN:FTP_DATA=FTP_DATA\ARCHIVE
    What I want is the this:
    C:\DATA\FTP_DATA\ARCHIVE\ACME\IN
    Any suggestions?

    Your syntax is not correct. Example:
    @echo off
    setlocal enableextensions
    set ARCHIVE_PATH=C:\DATA\FTP_DATA\ACME\IN
    echo %ARCHIVE_PATH%
    set ARCHIVE_PATH=%ARCHIVE_PATH:FTP_DATA=FTP_DATA\ARCHIVE%
    echo %ARCHIVE_PATH%
    endlocal
    -- Bill Stewart [Bill_Stewart]

Maybe you are looking for

  • WAK1  ----    How to send Free Goods details  to POS

    Gurus,   I have created the free goods data and everything works fine. When I create a whole sales order , I am getting the free goods. Now I want to send the information to POS . Can anyone help me how to send this I tried WPMA , but nothing is work

  • Regarding screen fields include in purchase order transaction

    Hai guys,     I need to add new field in purchase order transaction ( me21n, me22n, me23n ) . i have added the new field in screen painter. when i was creating the field and then i made the field to refer from dictionary , when i refer from dictionar

  • My iPod Classic froze and now won't turn on I've tried everything

    I went to listen to my iPod, which had almost full battery, turned it on, then pressed menu to go back and choose another song, but it froze for about 10seconds then went to a black screen. Now I can't get it to turn on, I tried restoring and everyth

  • Restoring Old Library

    Hi, I've been reading around the forum on this issue and tried most of the fixes but without success - so apologies if this is duplicating. I had to reset my laptop to factory settings. I want to restore my old itunes libary with playlists/purchases/

  • I cannot download Facebook since the iOS 6 update

    I've updated my iPhone to iOS 6 and now my Facebook and Instagram icons have disappeared. I've updated the software from the App Store and everything is legit but the only way I can open either app is from the App Store. How can I get the icons on my