How can I use quotes in a string?

From NSIS Wiki

There are three types of possible quotes: single quotes, double quotes and backward single quotes. Any command parameter can be surrounded by any of these three types. Therefore, to use a double quote in a string, simply surround the string with a single quote. It's also possible to escape quotes using a dollar and backslash. For example:
MessageBox MB_OK "I'll be happy" ; this one puts a ' inside a string
MessageBox MB_OK 'And he said to me "Hi there!"' ; this one puts a " inside a string
MessageBox MB_OK `And he said to me "I'll be damned!"` ; this one puts both ' and "s inside a string
MessageBox MB_OK "$\"A quote from a wise man$\" said the wise man" ; this one shows escaping of quotes
MessageBox MB_OK "That would be $$60" ; this the first $ will escape the second.

For more information see the Script File Format section in the documentation.

Build a RegExp that will grab NSIS strings

Okay let's start with a very simple version:

"[^"]*"

-> Match any char in between " and " that is not a "

Okay next step let's add a group "([^"])*" so we might get the string without quotes + we can do things like alternation with |

To take care for escape chars $\" and $$ the RegExp will be:

"([^$"]|$\"|$$)*"

->Match any char in between " and " that is not a " or $
but keep on matching if it's '$\"' or '$$'


Well that's not quite far from being perfect - but in a real world RE $ as well as \ have special meanings in a RE.

To use them as char you must escape them like this \\ or \$ so the working RE is this:

"([^$"]|\$\\"|\$\$)*"

Note: the '$' inside the char group (sometimes!) don't needs escaping (depending on RE-implementation. Do some testing on that to see what's working)

Now aggregating the double quotes, single quotes and backward single quotes Versions

"([^$"]|\$\\"|\$\$)*"
'([^$']|\$\\'|\$\$)*'
`([^$`]|\$\\`|\$\$)*`


Into one:

("([^$"]|\$\\"|\$\$)*"|'([^$']|\$\\'|\$\$)*'|`([^$`]|\$\\`|\$\$)*`)

and now you've got the ultimate NSIS RE Monster string that will match all NSIS-strings complete and correctly.

What to do with this RE now?

Use it for NSIS syntax highlighting in ya editor's configuration or for better comparing scripts in 'Beyond compare' by been able to priorise comparison by keywords, strings, Opt out comments. (<- of course you'll need a definition file or define keywords and what's a comment ya self)

Personal tools
donate
ads