Skip to content

Instantly share code, notes, and snippets.

@AndroBrain
AndroBrain / flags.md
Created November 24, 2024 10:01
Regex flags
Symbol Description Example Usage Matches
i Case-insensitive matching. /hello/i on HELLO HELLO
m Multi-line mode (^ and $ for each line). /^hello/m on hello\nworld hello
s Single-line mode (. matches newline). /a.+c/s on a\nbc a\nbc
g Global matching (find all matches). /\w+/g on hello world hello, world
y Sticky matching (starts at lastIndex). /hello/y on hello hello
@AndroBrain
AndroBrain / assertions.md
Created November 24, 2024 09:46
Regex assertions
Symbol Description Example Usage Matches
(?=...) Positive lookahead (asserts what follows). \w+(?=ing) on running runn
(?!...) Negative lookahead (asserts what doesn't follow). \w+(?!ing) on run run
(?<=...) Positive lookbehind (asserts what precedes). (?<=Mr\. )\w+ on Mr. John John
`(?
@AndroBrain
AndroBrain / groups.md
Created November 24, 2024 09:44
Regex Groups
Symbol Description Example Usage Matches
() Captures a group. (ab)+ on ababab ababab
(?:...) Non-capturing group. (?:ab)+ on ababab ababab without capturing
(?<name>...) Named capturing group. The name can be used within the match. (?<word>\w+) on hello hello and names the group word
\1, \2 Backreference to a group. (a)(b)\1 on aba aba
@AndroBrain
AndroBrain / quantifiers.md
Created November 24, 2024 09:39
Regex quantifiers
Symbol Description Example Usage Matches
* 0 or more occurrences. a* on aaab aaa
+ 1 or more occurrences. a+ on aaab aaa
? 0 or 1 occurrence. a? on aaab a, a, a
{n} Exactly n occurrences. a{2} on aaa aa
{n,} n or more occurrences. a{2,} on aaa aaa
{n,m} Between n and m occurrences. a{2,3} on aaa aa, a
@AndroBrain
AndroBrain / anchors.md
Last active November 24, 2024 09:38
Regex Anchors
Symbol Description Example Usage Matches
^ Start of a string. ^a\d on a1 a2 a3 a1
$ End of a string. a\d$ on a1 a2 a3 a3
\b Word boundary. \bword\b on wordplay word only
\B Non-word boundary. \Bword\B on password word within password
@AndroBrain
AndroBrain / character_classes.md
Last active November 24, 2024 09:36
Regex Character Classes
Symbol Description Example Usage Matches
. Character except newline (\n). a.b on aab, acb aab, acb
\d Digit (0-9). \d+ on abc123 123
\D Non-digit character. \D+ on abc123 abc!
\w Word character (alphanumeric + _). \w+ on _hello123!@ _hello123
\W Non-word character. \W+ on abc!@#123 !@#
\s Whitespace character. \s+ on hello world Space between hello and world
\S Non-whitespace character. \S+ on hello world hello, world
@AndroBrain
AndroBrain / ExternalAppOpener.kt
Created November 10, 2024 07:05
ExternalAppOpener
fun showExternalAppPicker(context: Context, uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW, uri)
// Get all matching apps
val matchingExternalApps = context.packageManager.queryIntentActivities(
intent,
PackageManager.MATCH_DEFAULT_ONLY,
)
displayExternalApps(context, matchingExternalApps)
}
@AndroBrain
AndroBrain / GeoIntentExample.kt
Created November 10, 2024 06:39
GeoIntentExample
val geoUrl = "geo:37.7749,-122.4194"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(geoUrl))
context.startActivity(intent)
@AndroBrain
AndroBrain / GenericIntentHandler.kt
Created November 10, 2024 06:36
GenericIntentHandler
fun openExternalApp(context: Context, uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW, uri)
context.startActivity(intent)
}
@AndroBrain
AndroBrain / AndroidManifest.xml
Created October 20, 2024 05:51
HTTP traffic
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<!-- Add this only if you're working with http and use it only in debug builds -->
<application
android:usesCleartextTraffic="true">
...