-1

I am using the latest Notepad++ and would be grateful for some RegEx development help. I need the RegEx to focus on only the * located to the right of colwidth attribute. Below are a couple examples of the XML colwidth attribute I'm talking about:

colwidth="0.83*"  (not missing * character)

colwidth="155.7"  (missing * character)

The RegEx needs to perform the following task:

If the closing " character to the right of the colwidth attribute code is missing the * character then I need the RegEx to insert a * character so I get this result: *"

However, if the closing " character of the colwidth attribute code already is preceded by a * character (as shown in example above) then I need the RegEx to do nothing to it.

Can a RegEx be made smart enough to only apply this change to only the text that begins like this: colwidth=" And then skip over whatever number/period combination and then only target the closing " character and add a * character if it is missing it or just skip over it if the * is already there preceding the closing "?

Any help will be greatly appreciated.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
Matrix
  • 181
  • 2
  • 10

1 Answers1

1

It's safer to use an XML-aware tool to edit XML. For example, in xsh, you can write

open file.xml ;
for //@colwidth[substring(., string-length(.)) != '*']
    insert text '*' append . ;
save :b ;
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Can this "XML-aware tool" you mention make global changes across 1,000 separate XML files? Or does one have to repeat the same operation 1,000 separate times? That is why I'm using NotePad++. It makes the change across many files as one single operation. Nevertheless, how much does this "XML-aware tool" cost? I would like to try it out. Where can I download it? Does it have a good user guide? Shell applications usually are hard to use. Do you know of a similar app that does the same operations but is in more user friendly Windows GUI? – Matrix May 24 '19 at 14:53
  • Of course it can. You just wrap the code into `for $file in { glob '*.xml' } { open $file ; ... ` or similar. – choroba May 24 '19 at 15:02
  • Where do I download the User Guide PDF and the "XML-aware tool" app itself? Is it free? Or is there a cost involved? – Matrix May 24 '19 at 15:31
  • It's free. You need Perl installed and its [XML::LibXML](http://p3rl.org/XML::LibXML) package. Then you can just install [XML::XSH2](http://p3rl.org/XML::XSH2) using any [CPAN](https://mcpan.org) client. – choroba May 24 '19 at 15:37