• Login
Community
  • Login

Search, Use Result to Add Code

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 4 Posters 552 Views
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.
  • R
    Richard Howard
    last edited by Dec 17, 2021, 5:34 PM

    I have an xml file that needs to be modified.
    I need to search for a callout that has an argument numref, as shown in the code below:

    <callout assocfig="fig3" numref="c3"/>
    

    Then, take the number after “c” and insert it before the numref in an argument, label, as below:

    <callout assocfig="fig3" label="3" numref="c3"/>
    

    Thanks in advance!

    A M 2 Replies Last reply Dec 17, 2021, 5:36 PM Reply Quote 0
    • A
      Alan Kilborn @Richard Howard
      last edited by Dec 17, 2021, 5:36 PM

      @richard-howard

      You have asked many such questions here.
      We are not a “substitution” service.
      Suggest you take what you’ve learned along the way, couple it with reading the documentation on regular expressions, and at least come up with a stab at it before asking for further help.

      1 Reply Last reply Reply Quote 1
      • R
        Richard Howard
        last edited by Dec 17, 2021, 5:42 PM

        Hey, I’m just happy I formatted the question properly, using Code. :)
        I do get your point and if this is inappropriate, ok.
        Thanks.

        1 Reply Last reply Reply Quote 0
        • M
          Michael Vincent @Richard Howard
          last edited by Dec 17, 2021, 5:50 PM

          @richard-howard said in Search, Use Result to Add Code:

          Thanks in advance!

          Replace:

          Find what: (numref\s*\=\s*\"c(\d)\")
          Replace with: label="\2" \1
          Search mode: Regular expression

          That’s your one freebie. Happy weekend, Happy Holidays … as the requirements change based on forthcoming further clarification, you can manipulate / improve the base I provided above to get you started.

          Cheers.

          1 Reply Last reply Reply Quote 1
          • R
            Richard Howard
            last edited by Dec 17, 2021, 5:52 PM

            Your generosity is appreciated!
            Happy Holidays to you all!!

            R 1 Reply Last reply Dec 20, 2021, 3:08 PM Reply Quote 1
            • R
              Richard Howard @Richard Howard
              last edited by Dec 20, 2021, 3:08 PM

              @richard-howard Just an update. The solution I was offered was very helpful. It did find and replace as desired, but the find only matched single numeric characters. Where the “C” was followed by double digits, it did not find it. So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.
              To find double digits, I replaced:

              (numref\s*\=\s*\"c(\d)\")
              

              with:

              (numref\s*\=\s*\"c(\d[0-9])\")
              

              Undoubtedly, this is not the only, or best, solution, but it does appear to work, though requires 2 passes to complete all matches. Just thought you might like to know that your nudge helped.
              Thanks.

              M P A 3 Replies Last reply Dec 20, 2021, 3:14 PM Reply Quote 2
              • M
                Michael Vincent @Richard Howard
                last edited by Dec 20, 2021, 3:14 PM

                @richard-howard said in Search, Use Result to Add Code:

                So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.

                Excellent! And in the spirit of collaboration and your research and reporting back, you could try replacing \d in my suggestion with \d+ where the + in REGEX syntax means "match at least one of the previous characters - in this case \d which is a digit. So \d+ is “one or more digits” - like “3”, “34”, “1337”, etc…

                Cheers.

                R 1 Reply Last reply Dec 20, 2021, 3:16 PM Reply Quote 3
                • P
                  PeterJones @Richard Howard
                  last edited by PeterJones Dec 20, 2021, 3:16 PM Dec 20, 2021, 3:16 PM

                  @richard-howard said in Search, Use Result to Add Code:

                  … \d[0-9] …

                  Good job on taking the initiative.

                  Two hints for learning more:

                  You might want to look at what \d means, in the docs regarding character escape sequences .

                  You might want to look at the docs regarding multiplying operators , looking for something that means “one or more”.

                  Combining those two will simplify your expression, and make it easier to catch c3, c31, and c314 all with the same expression.

                  … ah, @michael-vincent beat me to the punch… I’d still recommend actually reading the sections of the manual that I linked.

                  1 Reply Last reply Reply Quote 3
                  • R
                    Richard Howard @Michael Vincent
                    last edited by Dec 20, 2021, 3:16 PM

                    @michael-vincent Excellent! This forum has saved me uncounted hours. I appreciate it very much.

                    1 Reply Last reply Reply Quote 1
                    • A
                      Alan Kilborn @Richard Howard
                      last edited by Dec 20, 2021, 3:22 PM

                      @richard-howard said in Search, Use Result to Add Code:

                      So, after your ‘encouraging me’ to do a little research before just asking for the answer, I found something that works.

                      Awesome. You can only get better by taking such initiative.

                      1 Reply Last reply Reply Quote 2
                      2 out of 10
                      • First post
                        2/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors