How to replace text infile with regular Expression? - visual-build-professional

I want to replace a version number by a more current one (i.e. getting it from SVN, which is working fine). For testing purposes I try to replace what I find with something simple, but not even this is working.
This regular expression looks fine (e.g. tested in https://regex101.com/) and correctly matches my version number.
RegEx:
([1-9][0-9]|[0-9])\.([1-9][0-9]|[0-9])\.([1-9][0-9][0-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9]|[0-9])
Text to match (that is not matched):
Title="MyTitle 1.0.0"
According to https://regex101.com/ this should work. But Visual Build cannot find any match and no replacement is done.
I can confirm that file access is working, because Visual Build adds the text "error while replacing" to the specified file.
I'm using Visual Build Professional v10.

I'm not exactly sure what's wrong with your existing regex, but when I've had to do similar replacements I've tried to manufacture a replacement strategy that is a little different - basically to keep the regex as simple as possible. You could try something like this:
Text or regex to find:
Title=.*
e.g., just match the correct line of the file. Don't worry about the existing version number values.
Text to replace matches with:
Title="MyTitle %v1%.%v2%.%v3%"
I'm assuming you have three macros v1, v2, v3 for your version number parts. If you have one for the app title you could obviously insert that there too.

Related

Trying to use Regex match an iOS phone number using iOS Shortcuts

I'm creating an iOS shortcut that starts with checking whether the clipboard currently holds a copied phone number.
So far, my regex is the following:
^[\d\()-‑+  ]+$
Although while typing a regular phone number using the phone keyboard, e.g., +972 12-345-6789, it works just fine; it seems like when copied directly from the default Phone application, it does not find it as a match.
I should mention that after digging for a while, it seems like the phone number copied from the Phone application is associated with some extra special characters used for Left-To-Right Embedding and such. Using a Unicode decoder gave me the following string:
‪+972 12‑345‑6789‬
I'm not even sure whether this is the reason, but it might have some connection to it. If so - is there any way in which I can use iOS Shortcuts to decode the clipboard text into a Unicode format and remove those extra characters? And in case there is no connection between the two, what else might be the problem?
You can add the support for all these chars to the pattern:
^[\d()+\p{Zs}\p{Pd}\p{Cf}]+$`
Note:
\p{Zs} matches all whitespaces without the tabs and line breaks (add \t to the brackets if you need to support TAB)
\p{Pd} will match any dashes
\p{Cf} matches the bidirectional marks and more other control format chars.
Alternative solution
It is possible to paste the copied clipboard text into a Text action which removes any additional formatting.

How can these strings be different?

I am facing a weird problem.
I have extracted data from an Excel file. It should contain an IBAN account number.
Then I tried to analyze the set of account numbers (which the source guarantees to be good) with a Java library.
To keep the scope of the question narrow, I can't explain the following. The below strings are different
030​69
03069
The first is a copy & paste from the Excel file, the second is handwritten. Google returns different results for abi [above number] and in fact in the second case I can find that it is the bank code for Intesa Sanpaolo bank (exact page displaying the ABI code, localized, here).
So, to keep the scope narrow: how is that possible? Is it something to do with the encoding?
Try it yourself: do CTRL+F and try type "030", it will select both lines. Now type 6, it will match only the 2nd line.
Same happened in Notepad++
There's an U+200B ZERO WIDTH SPACE in between 030 and 69 in the first text.
Paste the text in https://www.branah.com/unicode-converter for example, or edit in a hexadecimal capable editor.
The solution for cleaning such strings could be for example to whitelist characters, so replace everything that isn't A-Z0-9 will be scrubbed.

TFS drop, exclude obj folder using minimatch pattern

I'm setting up TFS 2015 on-prem and I'm having an issue on my last build step, Publish Build Artifacts. For some reason, the build agent appears to be archiving old binaries and I'm left with a huge filepath:
E:\TFSBuildAgent\_work\1a4e9e55\workspace\application\Development\project\WCF\WCF\obj\Debug\Package\Archive\Content\E_C\TFSBuildAgent\_work\1a4e9e55\workspace\application\Development\project\WCF\WCF\obj\Debug\Package\PackageTmp\bin
I'm copying the files using the example minimatch pattern to begin with:
**\bin
I'm only testing at the moment so this is not a permanent solution but how can I copy all binaries that are in a bin folder but not a descendant of obj?
From research I think that this should work, but it doesn't (It doesn't match anything):
**!(obj)**\bin
I'm using www.globtester.com to test. Any suggestions?
On a separate note, I'll look into the archiving issue later but if anyone has any pointers on it, feel free to comment. Thanks
In VSTS there are two kinds of pattern matching for URLs that are built-in to the SDKs. Most tasks nowadays use the Minimatch pattern as described in Matt's answer. However, some use the pattern that was used by the 1.x Agent's Powershell SDK. That format is still available in the 2.x Agent's Powershell SDK by the way.
So that means there are 5 kinds of tasks:
1.x agent - Powershell SDK
2.x agent - Node SDK
2.x agent - Powershell 1 Backwards compatibility
2.x agent - Powershell 3 SDK - Using find-files
2.x agent - Powershell 3 SDK - Using find-match
The ones in bold don't Minimatch, but the format documented in the VSTS-Task-SDK's find-files method.
The original question was posted in 2015, at which point in time the 2.x agent wasn't yet around. In that case, the pattern would, in all likelihood, be:
**\bin\$(BuildConfiguration)\**\*;-:**\obj\**
The -: excludes the items from the ones in front of it.
According to Microsoft's documentation, here is a list of
file matching patterns you can use. The most important rules are:
Match with ?
? matches any single character within a file or directory name (zero or one times).
Match with * or +
* or + matches zero or more characters within a file or directory name.
Match with # sign
# matches exactly once.
Match with Brackets (, ) and |
If you're using brackets with | it is treated as a logical OR, e.g. *(hello|world) means "Zero or more occurrances of hello or world"
Match with Double-asterisk **
** recursive wildcard. For example, /hello/**/* matches all descendants of /hello.
Exclude patterns with !
Leading ! changes the meaning of an include pattern to exclude. Interleaved exclude patterns are supported.
Character sets with [ and ]
[] matches a set or range of characters within a file or directory name.
Comments with #
Patterns that begin with # are treated as comments.
Escaping
Wrapping special characters in [] can be used to escape literal glob characters in a file name. For example the literal file name hello[a-z] can be escaped as hello[[]a-z].
Example
The following expressions can be used in the Contents field of the "Copy Files" build step to create a deployment package for a web project:
**\?(.config|.dll|*.sitemap)
**\?(.exe|.dll|.pdb|.xml|*.resx)
**\?(.js|.css|.html|.aspx|.ascx|.asax|.Master|.cshtml|*.map)
**\?(.gif|.png|.jpg|.ico|*.pdf)
Note: You might need to add more extensions, depending on the needs of your project.

How can I search for <item1> AND <item2> using the Delphi XE2 IDE search?

I use searching all the time to locate stuff within my (huge) application source, so search effectiveness is very important to me. Presently in the Delphi XE2 IDE I like to use:
Find in Files
Include subdirectories.
Nothing else fancy, just a text keyword. This works ok but what I would really like to do is to extend what I'm doing now to include lines that contain 'A' AND 'B' where A and B are any group of characters (one type of boolean search). Exact matches against A and B are fine, because this now allows you to put in two very partial keywords and still find a unique occurence. I've been using this method in my own search engine for years. Is there an easy way of doing this in the Delphi IDE please?
Thanks
You can use regular expressions (just check the regular expressions checkbox on the right side of the Find window). The regex support is somewhat limited - it's documented for XE2 on the XE2 docwiki here.
I use GExperts Grep Search instead (part of the GExperts IDE experts set), which offers fuller regex support (although still not great) and a better display (IMO) of the search results. (Note the image of the Grep Search dialog contains a regular expression that will match WordA or WordB in either order in the file, so it satisfies your search logic within the limited regex support in GExperts. It matches single words on the line as well, but the results dialog makes it easy to find the lines you're interested in, and double-clicking a line will take you to that match in the IDE's code editor.)
The above results are based on a single file search and those results. For multiple files (in this case, just two), the dialog appears like this:

Define every symbol as a command in LaTeX

I'm working on a large project involving multiple documents typeset in LaTeX. I want to be consistent in my use of symbols, so it might be a nice idea to define a command for every symbol that has a specific meaning throughout the project. Does anyone have any experience with this? Are there issues I should pay attention to?
A little more specific. Say that, throughout the document I would denote something called permability by a script P, would it be an idea to define
\providecommand{\permeability}{\mathscr{P}}
or would this be more like the case "defining a command for $n$"?
A few tips:
Using \providecommand will define that command only if it's not been previously defined. So if you're not getting the results you expected, you may be trying to define a command that's been defined elsewhere.
If you wrap the math in your commands with \ensuremath, it will do the right thing regardless of whether you're in math mode when you issue the command:
\providecommand{\permeability}{\ensuremath{\mathscr{P}}}
Now I can easily use \permeability in text or $\permeability$ in math mode.
Using your own commands allows you to easily change the typographical representation of something later. For instance:
\newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}}
would print \vect{x} as a boldfaced x. If you later decide you prefer arrows above your vectors, you could change the command to:
\newcommand{\vect}[1]{\ensuremath{\vec{#1}}}
I have been doing this for anything that has a specific meaning and is longer than a single symbol, mostly to save typing:
\newcommand{\objId}{\mbox{$\mathit{objId}$}\xspace}
\newcommand{\insOp}[1]{#1\mbox{$^+$}\xspace}
\newcommand{\delOp}[1]{#1\mbox{$^-$}\xspace}
However then I noticed that I stopped making inconsistency errors (objId vs ObjId vs ObjID), so I agree that it is a nice idea.
However I am not sure if it is a good idea in case symbols in the output are, well, single Latin symbols, as in:
\newcommand{\numOfObjs}{$n$}
It is too easy to type a single symbol and forget about it even though a command was defined for it.
EDIT: using your example IMHO it'd be a good idea to define \permeability because it is more than a single P that you have to type in without the command. But it's a close call.

Resources