Community

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

    Search, Use Result to Add Code

    Help wanted · · · – – – · · ·
    4
    10
    185
    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.
    • Richard Howard
      Richard Howard last edited by

      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!

      Alan Kilborn Michael Vincent 2 Replies Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Richard Howard last edited by

        @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
        • Richard Howard
          Richard Howard last edited by

          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
          • Michael Vincent
            Michael Vincent @Richard Howard last edited by

            @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
            • Richard Howard
              Richard Howard last edited by

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

              Richard Howard 1 Reply Last reply Reply Quote 1
              • Richard Howard
                Richard Howard @Richard Howard last edited by

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

                Michael Vincent PeterJones Alan Kilborn 3 Replies Last reply Reply Quote 2
                • Michael Vincent
                  Michael Vincent @Richard Howard last edited by

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

                  Richard Howard 1 Reply Last reply Reply Quote 3
                  • PeterJones
                    PeterJones @Richard Howard last edited by PeterJones

                    @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
                    • Richard Howard
                      Richard Howard @Michael Vincent last edited by

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

                      1 Reply Last reply Reply Quote 1
                      • Alan Kilborn
                        Alan Kilborn @Richard Howard last edited by

                        @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
                        • First post
                          Last post
                        Copyright © 2014 NodeBB Forums | Contributors