Wildcard find



  • I looked for a solution but could not fine one. Sorry if this is a repeated question.

    I grabbed some notes from another document that brought in with it the page references to each note. I want to global delete all such references.

    Eg’s “Page 234 · 2598” and “Page 231 · 2548”

    I want to delete “Page???” Page followed by eleven characters.



  • @Brian-Nobles said:

    I want to delete “Page???” Page followed by eleven characters.

    First off, if you literally mean page as when the document is printed, then not possible. However there might be a method if the references at the start of the document as such that they could be used to identify the portion of the document that needs removing.

    So for example we might have (at the start of the doc, in index)

    xyz in abc pgs 1 - 5
    cde about the jki pgs 56 - 342

    If the “xyz in abc” text appeared at the start of the actual note within the doc then a search for all text from there to the next line “cde about the jki”, but excluding that last portion Once that was selected it is easily removed.

    Also consider, if removing one such note, then the page references remaining are no longer valid!

    Terry



  • Here is an example wherein the note is

    Always have coins on hand.
    Page 222 · 2458

    The note “Always have coins on hand.”
    came from “Page 222 · 2458”

    I don’t care what page it is referring to, I just want to keep the note “Always have coins on hand.”



  • @Brian-Nobles said:

    I don’t care what page it is referring to, I just want to keep the note “Always have coins on hand.”

    Okay. Then match on the Page, 11 characters, and the end-of-line, and delete them.

    Your examples imply that Page is the very first token on the line, and that you want the whole line deleted. If this isn’t true, then give us a better example, with actual details. If this is true, then this regex worked on my example:

    One way to do that would be

    • Find = (?-s)^Page.{11}$(\R|\z)
    • Replace = empty
    • Mode = regular expression

    which will convert

    Always have coins on hand.
    Page 222 · 2458
    Always have coins on hand.
    Page 123 · 4567
    Always have coins on hand.
    Page 456 · 7890 WITH EXTRA WONT DELETE
    Always have coins on hand.
    Page 789 · 2458
    

    into

    Always have coins on hand.
    Always have coins on hand.
    Always have coins on hand.
    Page 456 · 7890 WITH EXTRA WONT DELETE
    Always have coins on hand.
    

    -----
    FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:

    This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.

    If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

    Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.



  • Brilliant, and thanks for the extra info.


Log in to reply