Can't search for a url that's in a field

Hi,

I have a note field that contains a link to a different site, but when I try to search for the note that contains a certain url my search fails. I don’t know why it’s happening. It happens for certain links but not for others.

For example, the issue is happening with this link

http://localhost:8081/#:[created[20240521160030107]],

but not with https://notes.andymatuschak.org/zB2cf1tzHqvLRg5Px4rBNbq

The way that I am searching for the url is re:URL

re:http://localhost:8081/#:[created[20240521160030107]]

re:https://notes.andymatuschak.org/zB2cf1tzHqvLRg5Px4rB

Read the part of the manual that talks about searching.

some characters like *, _ and " have a special meaning in Anki. If you need to locate those characters in a search, you need to tell Anki not to treat them specially.

To match something including spaces, enclose the “entire term” in double quotes.

I have quoted some parts that might be relevant to you but do read the manual on your own.

I read the manual before posting the question but I still don’t understand what I am doing wrong to be honest. I am still learning about regular expressions, so they confuse me a little bit. I just re-read the searching section of the manual and tried the following searches and I am still stumped.

re:http://localhost:8081/#:[created[20240521160030107]]

"re:http://localhost:8081/#:[created[20240521160030107]]"

re:"http://localhost:8081/#:[created[20240521160030107]]"

"re:http://localhost:8081/#\:[created[20240521160030107]]"

Sorry mate. AFAIK using " " should’ve worked.
It works for me when I’m searching for text. BTW you are sure that piece of text exists in the field of a card (in the deck you’re searching)?

Here’s some more info about my issue:

I have a deck called playground (the deck I use to test new features and mess around with Anki without having it affect my real cards).

In that deck, I created a note that has a field called relatedTiddler. In the field relatedTiddler of the note, I put a URL like

http://localhost:8081/#:[created[20240521160030107]]

in it.

(I also tried to search for the URL by the field by doing something like this
relatedTiddler:re:http://localhost:8081/#:[created[20240521160030107]]
and that didn’t work.)

I don’t search by the deck, if that’s what you are asking. But the note is in the playground deck.

I tried searching for http://localhost:8081/#:[created[20240521160030107]] myself and it seems the colon is creating the problem.

Yea, I think that might be it. I tried to escape it (don’t know if I did it correctly), but that didn’t work for me.

", * and _
Add a backslash before these characters to treat them literally. For example, _ will match any single character, but _ matches only an actual underscore.

Colons have to be escaped unless they are preceded by another, unescaped colon. So w:e:b is a word boundary search for e:b, w:e:b searches literally for w:e:b

You tried putting / ? Hmm… weird. I’ll try then.

Edit: Okay I can escape colons but what you do about the two // ?

two backslashes are considered one backslash AFAIK.

So, did it work for you? Were you able to search for the URL? What was your search query?

Are you trying to use regex on a template with JavaScript or are you using python for an add-on? This makes a difference here.

Not sure what you mean. I am not doing anything with JavaScript or Python (or at least I don’t think so). I am searching for a note that contains a specific URL using the browser.

1 Like

Oh. Now I get it. Yeah. I don’t know if the search bar uses javascript regex or python regex.

Try it either with this here: /http://localhost:8081/#:[created[20240521160030107]]/

Or this here:
r’http://localhost:8081/#:[created\[20240521160030107\]]’

Tell me which one works (or if it doesn’t work)

I tried them both and they didn’t work.

/http://localhost:8081/#:[created[20240521160030107]]/

r’http://localhost:8081/#:[created\[20240521160030107\]]’

This here?

re:http:\/\/localhost:8081\/#:\[created\[20240521160030107\]\]

EDIT:

I tested it in the card search. It works for me now.

1 Like

If you want to easily learn, how to do regex, use this page: https://regex101.com/ (and choose JavaScript on the left side, if you try to create regex for your card search :)! )

1 Like

Nah it didn’t. Backslashes were creating a problem. //localhost actually searches for /localhost because as I said “two /”= “one /”

regex is probably worth trying here.

1 Like

Will do!

1 Like

Yep, that worked for me too!

2 Likes