Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    FAQ Desk: Template for Search/Replace Questions

    FAQ
    search replace regex regular expression
    1
    1
    1789
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PeterJones
      PeterJones last edited by PeterJones

      Hello, and welcome to the FAQ Desk. If you are reading this, you were likely directed here to get a template to use when asking a search, search-and-replace, regular expression, regex, mark, or other “change data that matches X” question.

      You can copy the template below and paste it into your question in the Help Wanted section of the forum. Then go through and change anything that’s in ALL CAPS into something that’s meaningful for your question. Leave the special punctuation (` or ``` symbols especially), as they provide formatting for this forum that will help your message be understandable.


      Template

      Fellow Notepad++ Users,

      Could you please help me with the following search-and-replace problem I am having?

      DESCRIBE CIRCUMSTANCES OF YOUR QUESTION

      Here is the data I currently have (“before” data):
      ```
      COPY/PASTE EXACT DATA HERE
      IT CAN HAVE MORE THAN ONE LINE
      MAKE SURE IT ACCURATELY REPRESENTS YOUR DATA,
      EVEN IF YOU HAVE TO CHANGE SOME THINGS
      (LIKE CHANGING NAMES OR ADDRESSES OR ACCOUNT NUMBERS):
      BUT IF YOU DO CHANGE SOMETHING, MAKE SURE THE
      STRUCTURE AND LOOK OF THE DATA IS STILL ACCURATELY
      REPRESENTED
      ```

      Here is how I would like that data to look (“after” data):
      ```
      PUT SIMILAR TEXT HERE,
      BUT THIS SHOULD LOOK LIKE THE END RESULT
      OF THE SEARCH-AND-REPLACE PROCESS
      ```

      IF THERE IS SOMETHING THAT DOES NOT GET EXPRESSED WELL
      BY PASTING YOUR EXAMPLE TEXT BETWEEN THE ``` LINES ABOVE,
      PLEASE MAKE A SCREENSHOT OF YOUR NOTEPAD++ WINDOW AND
      PASTE IT HERE. BUT A PICTURE SHOULD ONLY ACCOMPANY
      YOUR EXAMPLE TEXT, YOU SHOULDN’T USE THE PICTURE IN
      PLACE OF YOUR EXAMPLE TEXT.

      To accomplish this, I have tried using the following Find/Replace expressions and settings

      • Find What = `SEARCH EXPRESSION HERE`
      • Replace With = `REPLACEMENT EXPRESSION HERE`
      • Search Mode = REGULAR EXPRESSION or NORMAL or EXTENDED
      • Dot Matches Newline = CHECKED or NOT CHECKED

      HERE IS WHY YOU THOUGHT YOUR EXPRESSION WOULD WORK

      Unfortunately, this did not produce the output I desired, and I’m not sure why. Could you please help me understand what went wrong and help me find the solution?

      Thank you.


      Hints / Guidelines

      Obviously, you can feel free to include additional information not present in the template.

      If you choose to leave out information from this template, it will be harder for people to answer your question, and you may get people pointing you back to this FAQ entry to provide more information.

      Here are some other hints and guidelines for asking such questions:

      • Be patient
      • Be polite
      • Show a willingness to learn
      • Answer all requests for clarification
      • Your example “before” and “after” data should include examples of data that should be changed, and example data that should not be changed by the replacement. Often, crafting a successful search/replace expression requires knowing both.
      • If there are edge cases or exceptions, make sure your example data includes those
      • When you share the expressions that you already tried, it’s good to explain why you thought it would work
      • It really is important for the example “before” and “after” data to be as plain text, not just as a screenshot. Otherwise, fellow Notepad++ Community members cannot easily copy/paste your example data to experiment with the search/replace expressions.

      Please note that the template above was written to try to encourage following these guidelines.

      Forum bug with \[ and \]

      The forum refuses to handle \[ and \] correctly. Even if you put it in `backticks`, it won’t render right, and the preview will not match what the forum will show when it’s posted.

      The best advice is if you want to post a regex where you want to match a literal [ or ], so that you would use \[ or \] in the regex, use an alternate regex syntax for the literal-close-square-bracket character, like \x5B and \x5D : this will work in the forum, and will work in the regex, without jumping through any hoops. It also might make it easier when reading your regex, so that the literal \[ \] doesn’t get confused with the regex character-class enclosing [ ... ] .

      Examples of the rendering:

      backslash count raw in backticks raw in backticks
      0 ] ] [ [
      1 ] ] [ [
      2 ] \] [ \[
      3 ] \\] [ \\[
      4 \] \\\] \[ \\\[

      The preview of that showed:
      40c67edc-fa38-488a-b1ee-6e6e295e1760-image.png

      But that’s not how it rendered, which actually showed up as:
      502969ef-7c34-4ac5-89bd-91a46b22d08f-image.png

      Similar happens in code-text-blocks

      0 | ]        | [
      1 | ]        | [
      2 | \]       | \[
      3 | \\]      | \\[
      4 | \\\]     | \\\[
      

      7c8a96db-3960-4f04-96ea-4fc70102f330-image.png

      Because of that issue, if you’re posting a regex in the forum, it’s highly recommended to use \x5B and \x5D in regexes where you wanted to match a literal [ or ] .

      Caveat

      Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first few (one to three) data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

      Related Resources

      • FAQ Desk: Formatting Forum Posts
      • FAQ Desk: Where to Find Regular Expression (RegEx) Documentation
      • Notepad++ Online User Manual: Searching
      1 Reply Last reply Reply Quote 4
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  guy038 guy038 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  astrosofista astrosofista 
      • Referenced by  astrosofista astrosofista 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Pinned by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Terry R Terry R 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  guy038 guy038 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Terry R Terry R 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  L S L S 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  guy038 guy038 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Сергей Рыбин Сергей Рыбин 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Infinite Infinite 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Infinite Infinite 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Lycan Thrope Lycan Thrope 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Olivier Chantraine Olivier Chantraine 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  faouzi sat faouzi sat 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  PeterJones PeterJones 
      • Referenced by  Lycan Thrope Lycan Thrope 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • Referenced by  Alan Kilborn Alan Kilborn 
      • First post
        Last post
      Copyright © 2014 NodeBB Forums | Contributors