Inserting text at the beginning of a line that begins with a letter



  • I am creating an html document, and I would like to insert an html tag in front of all the lines that don’t currently have a tag. I would think that I should be able to find any line that starts with a letter, as opposed to a “<” and then put an html tag of my choosing in front of it. Currently, I have a macro that does the trick, but using it means that I have to scroll to wherever I want the tag to appear and run the macro with a keystroke. It’s doable, but I think there might be a better way.

    Can I search for a line that starts with a letter and then insert an html tag there?



  • @John-Reder
    It certainly is possible to find a line which doesn’t start with a “<”, however you said:

    as opposed to a “<” and then put an html tag of my choosing in front of it.

    suggests you wish to put different tags in depending upon some criteria which you haven’t elaborated on. Depending on how you identify your line and from that the tag type it is possible, but it becomes a bit more difficult.

    You may need to come up with some more info on how you determine the tag type to insert. Only then can a judgement call be made as to whether a regular expression will help you.

    Terry



  • What I’m trying to do is insert: <li class=“FirstLevel”> before any line that doesn’t have any tag in front of it.

    <li class=“SecondLevel”>If ever I want to find my soul
    <li class=“ThirdLevel”>Or wind a path to my heart
    <li class=“FourthLevel”>So free
    Here is the line where I need to insert the tag.
    <li class=“ThirdLevel”>I’ll think of thee
    <li class=“SecondLevel”>And all will be forgiven.



  • @John-Reder
    try this regex. As it uses special characters you need to use the "Replace Function (default Ctrl and H keys) in “Regular expression” search mode. Also have wrap around ticked.
    Find What:^[^<]
    Replace With:<li class=“FirstLevel”>$0
    The red text above can be copied directly from here into the relevant fields.

    So what it does is start at the start of a line. It will then capture 1 character ONLY if that character is NOT a “<”. It then replaces that character with your tag, followed by the character back again. So ANY line not starting with “<” will be changed by the regex.

    See if that solves your request.

    Terry



  • That did the trick! I had inserted some blank lines to increase readability in the HTML document, but I just eliminated them, and everything went along well. I have about 10,000 lines of poetry to format, and I’m only up to 2,400 at the moment. This will make the rest of this task go much faster!


Log in to reply