ccd0 / 4chan-x

Adds various features to anonymous imageboards.
https://www.4chan-x.net/
Other
953 stars 131 forks source link

How do I filter within the first line of a comment? #3449

Open ars4l4n opened 4 months ago

ars4l4n commented 4 months ago

let's say I want to filter the term "ftm" within the first line of a comment, how do I do that in 4chan x?

I've tried somehow fitting it into this line I found on google #/^(.*)$/m but nothing worked

saxamaphone69 commented 4 months ago

image

Give /^ftm/i a go as I'm not sure if newlines even count when filtering. If you don't care where the "ftm" is, omit the ^.

ars4l4n commented 4 months ago

just /^ftm/i didn't do anything What am I supposed to do with the javascript regex. I entered the code (not sure if I did correctly cause I can#t see part of your image) and it blocked some of the ftm messages but most remained. No idea what was going on there

bakugo commented 4 months ago

The correct regex to use here is /^.*\bftms?\b/i. Use regex101.com if you want an explanation of how it works.

@saxamaphone69 That answer by ChatGPT is blatantly wrong in several ways (as LLM answers often are). Copy-pasting shitty AI generated answers you don't understand helps nobody.

ars4l4n commented 4 months ago

The correct regex to use here is /^.*\bftms?\b/i. Use regex101.com if you want an explanation of how it works.

awesome, that worked but the explanation on regex101 confuses me because it doesn't state which part of it is responsible for selecting the line. I noticed that I need it to filter line 2 and 3 as well

bakugo commented 4 months ago

the explanation on regex101 confuses me because it doesn't state which part of it is responsible for selecting the line.

Effectively this matches any string that starts at the start of the comment, ends with "ftm", and doesn't contain any newlines in between, so effectively just the first line.

If you want to match anywhere in the first 3 lines instead, you can use /^.*(\n.*){0,2}\bftms?\b/i instead, but at that point I don't see why you wouldn't just filter in the entire comment.

ars4l4n commented 4 months ago

Effectively this matches any string that starts at the start of the comment, ends with "ftm", and doesn't contain any newlines in between, so effectively just the first line.

complicated...

If you want to match anywhere in the first 3 lines instead, you can use /^.*(\n.*){0,2}\bftms?\b/i instead, but at that point I don't see why you wouldn't just filter in the entire comment.

awesome! it's because I'm trying to filter out ftm as a means to not have to interact with them but some bios contain "not looking for:ftm" at the end which would make me filter those out too if I didn't use your code.

saxamaphone69 commented 4 months ago

@bakugo all good, I have no idea how regex works and I find asking ChatGPT a good starting place, tweaking the bits I need, and doing more research from there. I then usually have regexr or regex1010 with an example of the comment/string I want to filter and tweak from there/ask ChatGPT for different options if I can't work it out on my own. I wasn't sure it was going to work for what was needed anyway and the fact that I forgot to ask it for "ftm" standalone, which is obvious now, doesn't help.

Glad you got your answer @ars4l4n, close the issue when you're ready.

ars4l4n commented 3 months ago

/^.*(\n.*){0,2}\bftms?\b/i

I use slightly changed versions of this and they work for the majority of things I wanted to filter but one thing still doesn't work. I used: /^.*(\n.*){0,2}\bms?\b/i and thought it should filter m in line 1:

m looking for I'm just looking for someone to trauma dump on me, then leave bonus points if you're literally insane because I'm having a boring night. Entertain me. contact _censored

I suspect that it's because m is the only "word" in the line but I don't know for sure. How do I solve this? Note that I don't want to filter the letter "m" when it's actually within a word

Also, how do I not filter 'm such as in I'm while still filtering /m/ or m