How to replace a regular exepresion in a string in power shell

Hi,
Not able to replace "\X25" with "%" in powershell script.
$new = $inst1
$word = '\X25'
also tried
$word = "\X25"
$replacement = "%"
$newText = $new -replace $word,$replacement
following error has been occurred:
The regular expression pattern \X25 is not valid.
At C:\TWClient-Build\rgx.ps1:15 char:1
+ $newText = $new -replace $word,$replacement
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (\X25:String) [], RuntimeException
    + FullyQualifiedErrorId : InvalidRegularExpression
Thank You

As noted in other posts, it's failing because the '\' is a reserved character and needs to be escaped.  There are other reserved characters that will also need to be escaped if you need to match them in your regular expression.
The [regex] class offers an static Escape() method that you can use to help you escape the reserved characters when doing a literal match:
$find = '\X25'
$Regex = [regex]::Escape($find)
$Regex
\\X25
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • How to replace first letters of a file name using Power shell or CMD

    Hi guys i am having a problem on mane files that i have which are duplicated. The main reason i cant group them by name is because they have numbers in front of their name which differs Eg
    01 - fileName.txt
    09 - fileName.txt
    02 - fileName.txt
    11 - fileName.txt
    i have a shed loads of them and would like to rename them by deleting the first three characters if they are numbers. I managed to create a powershell script to do that but the problem was that it would not work properly because the file would have a duplicated
    name after deleting the first few chars.
    can anyone help with a better script which would add a number to the end of the file name eg:
    fileName1.txt
    fileName2.txt
    fileName3.txt
    Ps all the files start with two numbers followed by a dash, however i have manually done a few which does not start with numbers and should be left alone by the script
    Thank you

    Here's a quick way to do it. I'm not sure what your existing code looks like but it sounds like you could incorporate this line into it.
    if ($oldfilename -match "[0-9]")
    $newfilename = $oldfilename.split("-")[1].trim().split(".")[0] + $oldfilename.split("-")[0].trim() + "." + $oldfilename.split("-")[1].trim().split(".")[1]
    else
    $newfilename = $oldfilename
    01 - fileName.txt becomes fileName01.txt
    fileName.txt stays fileName.txt

  • How to replace a particular striing with another string in jtextpane

    how to get replace a particular string with another string of a jtextpane without taking the text in a variable using getText() method .

    Thanks for your answer,
    "relevant object" means for you datasources, transfer rules and transformations ?
    With the grouping option "Save for system copy" I can't take easily all datasources, and others objects
    Will I have to pick all object one by one ?
    What would be the adjustement in table RSLOGSYSMAP ? For the moment it's empty.
    Regards
    Guillaume P.

  • How to replace SAP logo with customer logo

    Hi Gurus,
    How  to replace or insert a customer logo when creating input schdules EvDRE function.
    Cheers,
    Reddy.

    Reddy,
      You  shld  be  able  to copy and  paste  your  logo (after deleting  the  SAP  logo). ..as you  would  do  in  regular  excel.  If sometimes  it doesn't  work...use the   insert  picture  functionality......regular  excel/MS  way.
    Hope  this  helps.
    Vishal.

  • Is iphoto for iphone designed to replace the regular photos app?

    When i baught iphoto I expected it to accuattly replace the regular photos app i was really excited to get it and when i did wow not at all what i expexted from apple

    Well i baught it for many reasons but one of them. Was that i needed a refresh of the photos app i have had every iphone since the beggining and it bored me so when i saw iphotoit seemed that way like a newer way of seeing your photos while having awesome editing tools. The tools are really cool but was hoping it to be less lagy and to actuatlly replace the photos app At least that is how i saw it

  • Replace without regular expressions

    Hi,
    Is there a standard java library function that can perform a search and replace WITHOUT regular expressions. Its not so much that I dont want to search by regular expressions, but whenever i have a "$" sign in my replace string it'll chuck a poo. Also, i'm sure regexp has to be much slower.
    thanks,
    Robert.

    Wateva, I'll figure it out. I just thought I might be
    missing a really simple function or somthing.
    Thanks - and enjoy your 'duke dollars' :pFeel free to ask a more detailed question. I don't know how to answer something as general as what you posted. Provide some code, give us an example, tell us what you expect to happen. My sample showed you how to replace a dollar sign, which - as best as I can tell - is the problem you described having.
    I've always considered replaceAll() to be pretty simple...

  • Find/replace and regular expression problem

    Hello, i'm using find and replace with a regular expression
    for the first time. I have it checkmarked and it's finding my text
    but it's missing (not highlighting) the ')' at the end of the line.
    Here's my code:
    [($[0-9]+<font size="-2">US</font>)]
    it's supposed to find everything inside the square brackets -
    but it misses the closing parenthesis after </font>. I need
    to find this string and replace with nothing to remove the string
    from any/all pages. Is there a reason why it's missing the closing
    parenthesis? I was actually able to add a few more parenthesis
    (e.g. "))))") before OR after the closing square bracket and it
    still found the original text minus the closing bracket and the
    extra parenthesis didn't prevent the text from being found.
    Any help is appreciated!
    James...

    WyattEA wrote:
    > Hello, i'm using find and replace with a regular express
    for the first time. I
    > have it checkmarked and it's finding my text but it's
    missing (not
    > highlighting) the ')' at the end of the line. Here's my
    code:
    >
    > [($[0-9]+<font size="-2">US</font>)]
    That's not how square brackets work
    Try:
    \(\$\d+<font size="-2">US</font>\)
    A left parens, followed by the dollar sign, followed by at
    least one
    digit, followed by <font size="-2">US</font>,
    followed by a right parens.
    Mick
    >
    > it's supposed to find everything inside the square
    brackets - but it misses
    > the closing parenthesis after </font>. I need to
    find this string and replace
    > with nothing to remove the string from any/all pages. Is
    there a reason why
    > it's missing the closing parenthesis? I was actually
    able to add a few more
    > parenthesis (e.g. "))))") before OR after the closing
    square bracket and it
    > still found the original text minus the closing bracket
    and the extra
    > parenthesis didn't prevent the text from being found.
    >
    > Any help is appreciated!
    >
    > James...
    >

  • Replacing a Regular Expression by another

    I want to replace a regular expression by another regular expression..i.e
    if my input is : <tag>-1
    output should be : <tag-1>
    as the integer value changes for each tag I cannot hard code.I am able to match it using regular expression ">-\\d" but how do i replace it??
    Any workarounds would also be appreciated.
    Thanks in advance

    It's not totally clear what you're asking for, but it sounds like something like this:
    str = str.replaceAll("<tag>-(\\d+)", "<tag-$1>");Test it, and let me know if you have questions about what it's doing.
    Check out [http://www.regular-expressions.info] for a great regex tutorial.

  • How to replace NULL values from main table

    Dear all,
    I like to remove the NULL values from a main table field. Or the question is how to replace any part of the string field in MDM repository main table field.
    e.g.   I have a middle name field partly the value is NULL in some hundreds of records, I like to replace NULL values with Space
    any recommendation.
    Regards,
    Naeem

    Hi Naeem,
    You can try using Workflows for automatically replacing NULLs with any specific value.
    What you can do is: Create a workflow and set trigger action as Record Import, Record Create and Record Update. So, that whenever any change will occur in the repository; that workflow will trigger.
    Now create an assignment expression for replacing NULLs with any specific value and use that assignment expression in your workflow by using Assign Step in workflow.
    For exiting records, you will have to replace NULLs manually using the process given by Preethi else you can export those records in an Excel spreadsheet which have NULLs and then replace all NULLs with any string value and then reimport those records in your MDM repository.
    Hope this will solve your problem.
    Regards,
    Varun
    Edited by: Varun Agarwal on Dec 2, 2008 3:12 PM

  • How to replace obsolete download function module in ECC6.0?

    Hi Experts,
    How to replace obsolete download function module in ECC6.0?
    Thanks,
    Adi.

    Hi,
    DOWNLOAD is obsolete FM in ECC 6. To get the same functionality , we need to use
    CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG  method (It provides the File selection feature)
    and
    GUI_DOWNLOAD function module.(It downloads the internal table from program to presentation server)
    Please see the example below:
    Example:
    *CALL FUNCTION 'DOWNLOAD'
              EXPORTING
                   FILENAME            = p_filename
                   FILETYPE            = ‘DAT’
              TABLES
                   DATA_TAB            = T_DOWNL
              EXCEPTIONS
                   INVALID_FILESIZE    = 1
                   INVALID_TABLE_WIDTH = 2
                   INVALID_TYPE        = 3
                   NO_BATCH            = 4
                   UNKNOWN_ERROR       = 5
                   OTHERS              = 6.
    *End of deletion CH01-
    Replacement Method for above code:
    DATA: l_filename    TYPE string,
           l_filen       TYPE string,
           l_path        TYPE string,
           l_fullpath    TYPE string,
           l_usr_act     TYPE I.
    l_filename = P_filename.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
      EXPORTING
        DEFAULT_FILE_NAME    = l_filename
      CHANGING
        FILENAME             = l_filen
        PATH                 = l_path
        FULLPATH             = l_fullpath
        USER_ACTION          = l_usr_act
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        NOT_SUPPORTED_BY_GUI = 3
        others               = 4.
    IF sy-subrc = 0
          AND l_usr_act <>
          CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                        = l_fullpath
       FILETYPE                        = 'DAT'
      TABLES
        DATA_TAB                        = T_DOWNL
    EXCEPTIONS
       FILE_WRITE_ERROR                = 1
       NO_BATCH                        = 2
       GUI_REFUSE_FILETRANSFER         = 3
       INVALID_TYPE                    = 4
       NO_AUTHORITY                    = 5
       UNKNOWN_ERROR                   = 6
       HEADER_NOT_ALLOWED              = 7
       SEPARATOR_NOT_ALLOWED           = 8
       FILESIZE_NOT_ALLOWED            = 9
       HEADER_TOO_LONG                 = 10
       DP_ERROR_CREATE                 = 11
       DP_ERROR_SEND                   = 12
       DP_ERROR_WRITE                  = 13
       UNKNOWN_DP_ERROR                = 14
       ACCESS_DENIED                   = 15
       DP_OUT_OF_MEMORY                = 16
       DISK_FULL                       = 17
       DP_TIMEOUT                      = 18
       FILE_NOT_FOUND                  = 19
       DATAPROVIDER_EXCEPTION          = 20
       CONTROL_FLUSH_ERROR             = 21
       OTHERS                          = 22.

  • How to replace double quotes with a single quote in a string ?

    Hi All:
    Can some one tell me how to replace double Quote (") in a string with a single quote (') ? I tried to use REPLACE function, but I couldn;t get it worked.
    My example is SELECT REPLACE('STN. "A"', '"', ''') FROM Dual --This one throws an error
    Thanks,
    Dima.

    Whether it is maybe not the more comfortable way, I like the quoting capabitlity from 10g :
    SQL> SELECT REPLACE('STN. "A"', '"', q'(')') FROM Dual;
    REPLACE(
    STN. 'A'{code}
    Nicoals.                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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.

  • How to replace/remove/change font color of a character at in output

    Hi all,
    I am using rtf template to get the output of a report, however i have a condition for field "Narratives" where if field A contains 'X', I need to either get rid of the 'X', replace with '' or change the font of X to white.
    Meaning if the output is : My Name is BavaniX
    I need it to look like : My Name is Bavani
    I use the BI Publisher desktop tool to create the placeholders. Highly appreciate if someone could advise me on how to replace with '' or change X to white font or remove the X using the BI desktop tool.
    The placeholder right now looks like this <?(NARRATIVES)?>.
    Thank you.

    if you want to replace also look at
    How to remove underscore in xml tag
    Re: How to remove underscore in xml tag
    Edited by: AlexAnd on Aug 2, 2012 5:55 AM

  • My iPad2 Apple logo (the blue box with a capital A) was deleted in error. I would like to know how to replace it or get it back.  Thanks so much . . .

    My iPad2 Apple logo (the blue box with a capital A) was deleted in error. I would like to know how to replace it or get it back.  Thanks so much . . .

    Do you mean the App Store app on your iPad ? If you do then it can't be deleted, but you might have hidden it via Settings > General > Restrictions > Installing Apps 'off' - if that is 'off' then turn it back 'on' and the app should show on one of your iPad's home screens again

  • LIVE Video Tutorial! How to Replace and Configure a Video Card - HP Expert Day "How-To" Video Series – Today at 1:00pm PST

    Join us at 1:00pm Pacific time for a LIVE video tutorial of how to replace a video card and configure video settings! The video features HP experts who work with the products every day!
    I am an HP employee.

    #test

Maybe you are looking for