Matching an empty path only in a Chrome Extension match pattern - google-chrome-extension

I ONLY want to match
*://www.foo.com
with either no querystring like above, or any querystring:
*://www.foo.com/?*
Problem is, how do I match the first pattern above? My guess is I have to just match all paths then exclude all paths, then include the second pattern above.
Any better way to do this?

Your patterns are almost correct. The path name is required. Even when the omnibar shows www.foo.com, then the path is /.
*://www.foo.com/
*://www.foo.com/?*
Note: the last pattern matches /?test but not /index?test.
For more information, see Match patterns.

Related

Regular expression to match any tiktok video id and url

I'm trying to match all these with just one regex:
https://m.tiktok.com/h5/share/usr/6641141594707361797.html
https://m.tiktok.com/v/6749869095467945218.html
https://www.tiktok.com/embed/6567659045795758085
https://www.tiktok.com/share/user/6567659045795758085
https://www.tiktok.com/trending?shareId=6744531482393545985
https://www.tiktok.com/#burntpizza89/video/7067695578729221378?is_copy_url=1&is_from_webapp=v1
https://www.tiktok.com/#burntpizza89/video/is_copy_url=1&is_from_webapp=v1&item_id=7067695578729221378
https://vm.tiktok.com/ZMF6rgvXY/
And it works fine except for the last one. The current regex is:
"\bhttps?:\/\/(?:m|www|vm)\.tiktok\.com\/.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+)\b"gm
It's handling all these digits ids perfectly (.tiktok.com/#burntpizza89/video/7067695578729221378), but I also need to match somehow these types of links which contains some specific url (.tiktok.com/ZMF6rgvXY/) with just one regex. So for the match I would get or digit-only id, or the url which contains digits and characters.
try the last part:
~https?://(?:www\.)?tiktok\.com/\S*/video/(\d+)|https?://(?:www\.)?vm.tiktok.com/\S*/~

Lexer definition to match keyword or an abbreviation

For writing a parser I would like to not only match full keywords but also abbreviations thereof, for example
MY-KEYWORD
must at least match
MY-KEY
but also any exact match longer than that, namely
MY-KEYW or MY-KEYWO or MY-KEYWOR or the full MY-KEYWORD
Is this possible with a reasonable lexer fragment or will I have to define specific alternative matches ?
TIA
Alex
Easiest would be to do something like this:
MY_KEYWORD
: 'MY-KEY' ('W' ('O' ('R' 'D'?)?)?)?
;

svn2git kde rules errors - converting tags

I am using svn2git all fast export and I am getting the following error:
- I had my rules for tags along these lines:
match /(<folder>/Source/<folder>/[^/]+/)tags/
repository repo
prefix \1
branch refs/tags/\2
end match
How can I correct these rules?
As already told in the comments of your other question, it is probably the invalid backreference you use.
Your rule doesn't make sense.
You have one match group in your regex (thing in parentheses), but you use two back references (backslash + number).
I guess it's erroring out because of that.
Compare your tag rule to my example and you should see the difference.
You miss the ([^/]+)/ in the end of the rule

what does paper.path() with no arguments mean?

Im sure of paper.path("path string") .But some examples use path method with no arguments.
I looked into the docs paper.path, its saying the path string is optional, but it hasn't said what happens when there is no path string.
You're correct that it allows empty paths. The definition from W3C is:
svg-path:
wsp* moveto-drawto-command-groups? wsp*
allowing any amount of white space surrounding zero or one of the moveto/drawto command groups.
From that W3C documentation page:
Note that the BNF allows the path ā€˜dā€™ attribute to be empty. This is not an error, instead it disables rendering of the path.
In other words, it's a path with no elements in it. Without this, you'd probably have to have some kludge like m 0 0 if you wanted a path to do nothing.

Lua Pattern for extracting/replacing value in / /

I have a string like hello /world today/
I need to replace /world today/ with /MY NEW STRING/
Reading the manual I have found
newString = string.match("hello /world today/","%b//")
which I can use with gsub to replace, but I wondered is there also an elegant way to return just the text between the /, I know I could just trim it, but I wondered if there was a pattern.
Try something like one of the following:
slashed_text = string.match("hello /world today/", "/([^/]*)/")
slashed_text = string.match("hello /world today/", "/(.-)/")
slashed_text = string.match("hello /world today/", "/(.*)/")
This works because string.match returns any captures from the pattern, or the entire matched text if there are no captures. The key then is to make sure that the pattern has the right amount of greediness, remembering that Lua patterns are not a complete regular expression language.
The first two should match the same texts. In the first, I've expressly required that the pattern match as many non-slashes as possible. The second (thanks lhf) matches the shortest span of any characters at all followed by a slash. The third is greedier, it matches the longest span of characters that can still be followed by a slash.
The %b// in the original question doesn't have any advantages over /.-/ since the the two delimiters are the same character.
Edit: Added a pattern suggested by lhf, and more explanations.

Resources