Glob Pattern Matching in .Net

glob pattern matching in .NET

I found the actual code for you:

Regex.Escape( wildcardExpression ).Replace( @"\*", ".*" ).Replace( @"\?", "." );

Glob Pattern Matching String in either folder or file name

How about **/{*cache*/*,*cache*}.test.js ? This is assuming you are using minimatch library (which is likely if you are working with JavaScript). Try using globster.xyz to test and improve your pattern.

In the pattern I mentioned {} are a feature called brace expansion. This pattern will be expanded into two separate patterns: one for matching a directory name and the other for matching filename **/*cache*/*.test.js, **/*cache*.test.js. This is still not perfect because the folder containing cache will have to be exactly one level above the file itself but maybe it works for you.

How to make program accept glob (wildcards) at command line?

take a look at NuGet package Microsoft.Extensions.FileSystemGlobbing

https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.filesystemglobbing.matcher

Matching strings with wildcard

You could use the VB.NET Like-Operator:

string text = "x is not the same as X and yz not the same as YZ";
bool contains = LikeOperator.LikeString(text,"*X*YZ*", Microsoft.VisualBasic.CompareMethod.Binary);

Use CompareMethod.Text if you want to ignore the case.

You need to add using Microsoft.VisualBasic.CompilerServices; and add a reference to the Microsoft.VisualBasic.dll.

Since it's part of the .NET framework and will always be, it's not a problem to use this class.

Quanteda: How can I use square brackets with glob-style pattern matching using tokens_lookup?

1) No, you cannot use brackets with glob pattern matching. However, they work perfectly with regex pattern matching.

2) No, [a-z] will not match umlauts.

Here's how to do it, stripping away all from your question that is not necessary to answering the question.

library("quanteda")
## Package version: 2.0.1

text <- "Ich mag Äpfel und Apfelkuchen"

toks <- tokens(text)

dict_1 <- dictionary(list(fruits = c("[aä]pfel*")))
dict_2 <- dictionary(list(fruits = c("[a-z]pfel*")))

tokens_lookup(toks, dict_1, valuetype = "regex", exclusive = FALSE)
## Tokens consisting of 1 document.
## text1 :
## [1] "Ich" "mag" "FRUITS" "und" "FRUITS"
tokens_lookup(toks, dict_2, valuetype = "regex", exclusive = FALSE)
## Tokens consisting of 1 document.
## text1 :
## [1] "Ich" "mag" "Äpfel" "und" "FRUITS"

Note: No need to import all of the tidyverse just to get %>%, as quanteda makes this available through re-export.

Powershell glob pattern matching

-Filter doesn't support filtering with regex or Character ranges such as [A-Z] or [0-9]. Thanks mklement0 for pointing it out.

From the parameter description of Get-ChildItem official documentation:

The filter string is passed to the .NET API to enumerate files. The API only supports * and ? wildcards.

Try with this:

Get-ChildItem -Path 'C:\Program Files\' -Filter log4j-core-*.*.??.jar -Recurse -ErrorAction SilentlyContinue -Force |
Where-Object {
$_.Name -match '\.\d{1,2}\.jar$'
# => Ends with a . followed by 1 or 2 digits and the .jar extension
}


Related Topics



Leave a reply



Submit