How to search for special characters in Github [duplicate] - github

This question already has answers here:
How to search on GitHub to get exact string matches, including special characters
(10 answers)
Closed last year.
Is there any possibility to search github repos for strings containing a special characters (e.g. "example.com" or "Example: ").As far as I know Github's search does not support it and Google ignores this as well.
Thanks in advance.

The GitHub Help says :
You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ] #. The search will simply ignore these symbols.
Alternatively, you can git clone some repositories and grep them.

One way of doing this is to use a space instead of the character and put your search term in quotes. It will give you the closest results.
I had a library call sg.createNode so I've searched for "sg createNote" which mostly returned results include sg.createNote

Related

Why doesn't GitHub display results for package search in code tab?

I want to search on GitHub: "#angular-architects/ddd" but I got no results on Code tab:
It is obvious that there are many results, and this is one of them:
https://github.com/mikezks/20220920/blob/main/package.json#L53
Did I use the search wrong, or is it a known bug on GitHub?
Because, per the search docs:
You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ] #. The search will simply ignore these symbols.
The forward slash and at sign are ignored, and there are no hits for angular-architectsddd. If you search for the scope and package name separately instead, you get some results: https://github.com/search?q=%22angular-architects%22+ddd&type=Code (currently 304 hits)
Note if you're looking for usages of this package in other NPM-based repositories, you can scope the search to package files: https://github.com/search?q=%22angular-architects%22+ddd+filename%3Apackage.json&type=Code
(currently 204 hits)

Microsoft graph Mail Search Strict value

I have an issue with the search parameters. I want to pass a phrase in my query. For exemple i'm looking for emails where the subject is "Test 1".
For this i'm doing a get on this ressource.
https://graph.microsoft.com/v1.0/me/messages?$search="subject:Test 1"
But the behaviour of this query is : Looking for mails that contains "Test" in the subject OR 1 in any other fields.
Refering to the KQL Syntax
A phrase (includes two or more words together, separated by spaces; however, the words must be enclosed in double quotation marks)
So, to do what i want i have to put double quotes (") around my phrase to do a strict value search. Like below
subject:"Test 1"
The problem it's at this point. Microsoft graph api already use double quotes (") after the parameters $search.
?$search="Key words"
So I can't do what is mentioned in the KQL doc.
https://graph.microsoft.com/v1.0/me/messages?$search="subject:"Test 1""
It's throwing an error :
"Syntax error: character '1' is not valid at position 15 in '\"subject:\"test 1\"\"'.",
It's an expected behaviour. I was pretty sure it will not work.
If someone has any suggestions for a solution or a workaround, I'm a buyer.
What I've already tried so far :
Use simple quote
Remove the quotes right after $select=
Remove the subject part $select="Test 1", same behaviour as the first request mentioned in this post. It will looks for emails that contain "test" or "1".
Best regards.
EDIT :
After sasfrog's anwser :
I used $filter : It works well with simple operator AND, OR.I have some errors by using the Not Operator. And btw you have to use the orderby parameter to show the result by date and add the field in filter parameters.
Exemple 1 (working, what I asked for first) :
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc &$filter=receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')
Exemple 2 (not working)
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc &$filter=(receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')) NOT(contains(from/EmailAddress/address,[specific address]))
EDIT 2
After some test with the filter parameters.
The NOT operator is still not working so to workaround use "ne" (non-equals)
the example 2 becomes :
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc&$filter=(receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')) AND (from/EmailAddress/address ne [specific address])
UPDATE : OTHER SOLUTION WITH $search
Using $filter is great but it looks like it was sometimes pretty slow. So I found a workaround aboutmy issue.
It's to use AND operator between all terms.
Exemple 4 :
I'm looking for the mails where the subject is test 1;
Let value = "test 1". So you have to splice it by using space separator. And after write some code to manipulate this array, to obtain something like below.
$search="(subject:test AND subject:1)"
The brackets can be important if you use a multiple fields search. And VoilĂ .
Not sure if it's sufficient for what you're doing, but how about using the contains function within a filter query instead:
https://graph.microsoft.com/v1.0/me/messages?$filter=contains(subject,'Test 1')
Sounds like you're already looking at the doco but here it is just in case.
Update also, this worked for me using the search method:
https://graph.microsoft.com/v1.0/me/messages?$search="subject:'Test 1'"

Searching for a literal hyphen in powershell

I am using powershell to split a multipage word document into single pages and then deleting all the pages I don't need. The problem is I am copying the text and searching for a pattern and the hyphen is throwing me off. This is the relevant code. If I remove the hyphen and just search for "Order Number", it works but it comes back with two pages instead of just the one I want with the pattern "Order Number -". I have tried a lot of configurations, escaping the hypen `-, --%, etc but nothing works, everything I run that includes the hyphen just outputs 8 DeleteMe pages, instead of 1 Docuemnt and 7 DeleteMe
$Pattern = "Order Number -"
$rngPg.End = $word.Selection.Start
$rngPg.Copy()
#Get Name
$regex = [Regex]::Match($rngPg.Text, $Pattern)
if($regex.Success)
{
$id = "Document" + $i
}
else
{
$id = "DeleteMe_" + $i
}
Change your pattern to:
$Pattern = 'Order Number [\u2010-\u2015-]'
Explanation:
Word has an AutoFormat feature that loves to automagically turn hyphens into dashes - that may be the case here.
English language Office turns hyphens into unicode characters with the codepoint value 0x2013, but it may vary depending on locale and installed language packs, thus the character set from 0x2010 to 0x2015 + -

Using Github API code search, find the exact string `throw "`

I want to find the exact strings, throw ' and throw " in javascript files in a given repo using the Github API.
It says:
You can't use the following wildcard characters as part of your search
query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The
search will simply ignore these symbols.
I'm supposing there is no way to find these exact strings using the API?
I have tried various searches with no luck. Trying to escape the " with \ doesn't work either.
https://api.github.com/search/code?q=%22throw+%27%22+in:file+language:js+repo:angular/angular.js
All of the queries I try return, for instance, https://github.com/angular/angular.js/blob/master/docs/config/tag-defs/tutorial-step.js which just finds the throw and disregards the '.
An alternative to this strategy is to find where there is NOT Error on the line, so that the search is throw NOT Error to try to find where someone is throwing a string and not throw new Error(. This strategy doesn't work for some reason. For instance,
https://api.github.com/search/code?q=%22throw%20NOT%20Error%22+in:file+language:js+repo:driverdan/node-XMLHttpRequest
There are many times that a plain string is thrown in https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js but, the file does contain the string Error; so, I guess this is enough to make the result empty. I'm seeing a way to "search" in my client program as a workaround; but, I would rather get the results from the API.
I'm supposing there is no way to find these exact strings using the API?
Correct, that's not possible currently.

What is the right regex to match a relative path to an image file?

I have this path ../../Capture.jpg. So far I've figured out this incomplete regex: '[../]+'. I want to check if user puts in the right path like ../../image file name. The file extensions can be jpg, png, ..
your [../]+ is not sufficient or correct for the job at hand, if you REALLY want to match a bunch of ../ at the start of a filename.
It's not completely clear what you want to do exactly, but the following will match one or more ../ at the start of a string:
/^((?:\.\.\/)+)/
basically:
^ to anchor to the start of the string being tested - will not match any ../ INSIDE the string
( and the balancing ) at the end: capture the contents within. All your ../../ will be available in a variable called $1
then I'm using (?: ) to wrap the next content. This groups the bit inside, but does NOT save the value inside a $1, $2, etc. More information soon...
The REAL pattern of interest is
\.\.\/
Since . and / are magic characters, they need 'escaping' with backslash. This tells Perl that the . and / do NOT have a special meaning at this point.
I've used the (?: ) wrapper to group them together, so that the + operates on all 3 characters of interest. The + operator means "one or more repetitions".
So, my pattern will match one or more repetitions of ../ which are anchored to the start of the string. Furthermore, the exact contents matched will be available in $1 if you are interested in doing something with that (eg count how many ../ you have)
Please ask if you have further questions, or I have misunderstood your goals.
EDIT: to suit your new requirements, and add a bit of bonus:
m!^\.\./\.\./(([^/]+)\.([^.]+))$!
Note first that I've used m!pattern! instead of /pattern/. Firstly, if Perl sees /pattern/ it assumes it's m/pattern/ but you can use an alternative character to wrap the patterns. This is useful if you actually want to use / in your pattern without having to go nuts with backslashes.
so:
^ exactly match only from the start
followed by exactly ../../
next I've used ( ) wrappers to capture the bits following. Explanation after...
ignoring the ( and ) now:
[^/]+ one or more repetitions (+) of any character that isn't /
. literally a dot - the one before the extension
[^./]+ one or more repetitions of any character that isn't . or /
Notice how the [^/]+ allows for any character including . but prevents another directory part from sneaking in. Thus, the filename could be foo.bar.jpg and it will be collected properly.
Notice how [^./]+ allows for any character in the extension except a dot - and also excluding / to prevent another directory segment from sneaking in.
Finally, $ is used to ensure we've reached the end of the pattern.
as for the captures:
$1 will contain all of foo.bar.jpg
$2 will contain foo.bar
$3 will contain jpg (not .jpg) but I'll leave it up to you to figure out what to change if you wish to capture the dot as well.
FINALLY - in a typical script, you might do something like:
if($filename =~ m!^\.\./\.\./(([^/]+)\.([^./]+))$!) {
print "You correctly entered ../../$1 giving basename=$2 and extension=$3 - Bravo!\n";
}
else {
print "you've failed to read the instructions properly\n";
}
As a bonus, I even tested that, and found 2 spolling mistaiks you'll never have to see
cheers.
# convert relative file paths to md links ...
# file paths and names with letters , nums - and _ s supported
$str =~ s! (\.\.\/([a-zA-Z0-9_\-\/\\]*)[\/\\]([a-zA-Z0-9_\-]*)\.([a-zA-Z0-9]*)) ! [$3]($1) !gm
If you don't care the path prefix, use:
$path =~ /\.(jpg|png)$/
or
substr($path, -4) ~~ ['.jpg', '.png']
With exactly '../../', use:
$path =~ m!^\.\./\.\./[^/]*\.(jpg|png)$!
With any number of '../'s, use:
$path =~ m!^(\.\./)*[^/]*\.(jpg|png)$!