Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-10-10 01:38:52 EDT

Explore

PostsPeople
LatestRanked
@uskes.bsky.socialSep 14, 2026, 3:31 AM

【記事紹介】【InDesign】正規表現スタイルは、その実、コードポイントで文字を判別しているっぽいです。WinとMacが併存する作業環境では、正規表現に注意してください。#InDesign #RegExp http://uske-s.hatenablog.com/entry/2017/06/13/135654

@uskes.bsky.socialSep 10, 2026, 3:22 AM

【記事紹介】【InDesign】①や❶、⑴なんかをコードポイントで検索するチートシートです。スクリプトにしてしまうと楽ちんです。 #InDesign #RegExp #ExtendScript http://uske-s.hatenablog.com/entry/2018/04/10/173559

@s0-and-s0.bsky.socialSep 9, 2026, 11:43 PM

So after much fiddling about, and help from another dev, it seems this is the best that can be done in pure TypeScript to expose RegExp constructor(s) and flag(s)

Not happy that it be incomplete, but am satisfied enough that it'll cover most normal use-cases

#devexp #regexp #typescript #webdev

````typescript
/**
 * Thanks to @GucciMAANG for showing `\d` and others are treated as `d`
 */
export type Escape_Entries = {
	'\n': '\\n';
	'\r': '\\r';
	'/': '\\/';
	/* WARNING: Following auto-expand when input, but no easy way to detect here */
	// '\b': '\u0008';
	// '\f': '\u000c';
	// '\v': '\u000b';
	/* WARNING: Following expect two to four more characters, and no easy way to detect here */
	// '\u': '\u0000';
	// '\x': '\u00';
};

/* When uncommented resolves to; "\b \f \v \\u \\x" */
// type Test = Escape_All<'\b \f \v \u \x'>;

export type Maybe_Escape_Character<T extends string>
	= T extends keyof Escape_Entries
	? Escape_Entries[T]
	: T;

export type Escape_All<S extends string>
	= S extends `${infer Head}${infer Tail}`
	? `${Maybe_Escape_Character<Head>}${Escape_All<Tail>}`
	: S;

export type Format_Expression<Type extends string> = `((\\b|\\s)(${Type})(\\b|\\s))`;

export type RegExp_With_Hints<
	Type extends string,
	Flags extends string = '',
	_Formatted = Format_Expression<Escape_All<Type>>,
> = RegExp & {
	source: _Formatted;
	toString(): `/${_Formatted}/${Flags}`;
};

export type Expression_Entries<
	Type extends Record<string, string>,
	Flags extends string = '',
> = {
	[Key in keyof Type]: RegExp_With_Hints<Type[Key], Flags>;
};

const constructors = {
	some_thang_simple: 'some\\s+thang\\s+simple',
	other_thang: 'woot\nnew\rlines?',
} as const;

const flags = 'gi' as const;

export const expressions = Object.entries(constructors).reduce((accumulator, [key, value]) => {
	try {
		const expression = `((\\b|\\s)(${value})(\\b|\\s))`;
		accumulator[key] = new RegExp(expression, flags);
	} catch (error) {
		console.error({ key, value, error });
		throw error;
	}
	return accumulator;
}, {} as Expression_Entries<typeof constructors, typeof flags>) as const;

/* Is; "((\\b|\\s)(woot\\nnew\\rlines?)(\\b|\\s))" */
// expressions.other_thang.source

/* Is; "/((\\b|\\s)(some\\s+thang\\s+simple)(\\b|\\s))/gi" */
// expressions.some_thang_simple.toString()
```