
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
@textlint/regexp-string-matcher
Advanced tools
Regexp-like string matcher library.
Install with npm:
npm install @textlint/regexp-string-matcher
Interface:
export interface matchPatternResult {
match: string;
startIndex: number;
endIndex: number;
}
/**
* Match regExpLikeStrings and return matchPatternResults
* @param text target text
* @param regExpLikeStrings an array of pattern string
*/
export declare const matchPatterns: (text: string, regExpLikeStrings: string[]) => matchPatternResult[];
Example:
import { matchPatterns } from "@textlint/regexp-string-matcher";
const inputText = `
GitHub is a web-based hosting service for version control using git.
It is mostly used for computer code.
GitHub launched in 2018-04-10.`;
// RegExp like strings
const inputPatterns = [
"git", // => /git/g
"/github/i", // => /github/ig
"/\\d{4}-\\d{2}-\\d{2}/" // => /\d{4}-\d{2}-\d{2}/g
];
const results = matchPatterns(inputText, inputPatterns);
assert.deepStrictEqual(results, [
{ match: "GitHub", startIndex: 1, endIndex: 7 },
{ match: "git", startIndex: 65, endIndex: 68 },
{ match: "GitHub", startIndex: 107, endIndex: 113 },
{ match: "2018-04-10", startIndex: 126, endIndex: 136 }
]);
This library aim to represent RegExp in JSON and use it for ignoring words.
g
(global) flag is added by default, Because ignoring words is always global in a document.
Input | Ouput | Note |
---|---|---|
"str" | /str/g | convert string to regexp with global |
"/str/" | /str/g | |
"/str/g" | /str/g | Duplicated g is just ignored |
"/str/i" | /str/ig | |
"/str/u" | /str/ug | |
"/str/m" | /str/mg | |
"/str/y" | /str/yg | |
--- | --- | --- |
"/\\d+/" | /\d+/g | You should escape meta character like \d |
:warning: You should escape meta character like \d
in RegExp-like string.
For example, If you want to write \w
(any word) in RegExp-like string, you should escape \w
to \\w
.
Text:
This is a pen.
RegExp-like String:
[
"/a \\w+/"
]
Results:
[ { match: 'a pen', startIndex: 8, endIndex: 13 } ]
text:
GitHub is a web-based hosting service for version control using git.
It is mostly used for computer code.
GitHub launched in 2018-04-10.
pattern:
[
"GitHub"
]
results: 2 hits
**GitHub** is a web-based hosting service for version control using git.
It is mostly used for computer code.
**GitHub** launched in 2018-04-10.
text:
GitHub is a web-based hosting service for version control using git.
It is mostly used for computer code.
GitHub launched in 2018-04-10.
pattern:
[
"/git/i"
]
results:: 3 hits
**Git**Hub is a web-based hosting service for version control using **git**.
It is mostly used for computer code.
**Git**Hub launched in 2018-04-10.
You should escape special charactor like \d
in RegExp-like string.
text:
GitHub is a web-based hosting service for version control using git.
It is mostly used for computer code.
GitHub launched in 2018-04-10.
pattern:
[
"/\\d{4}-\\d{2}-\\d{2}/"
]
results:: 1 hit
GitHub is a web-based hosting service for version control using git.
It is mostly used for computer code.
GitHub launched in **2018-04-10**.
text:
===START===
1st inline text.
===END===
===START===
2nd inline text.
===END===
pattern:
[
"/===START===[\\s\\S]*?===END===/m"
]
results:: 2 hits
**===START===
1st inline text.
===END===**
**===START===
2nd inline text.
===END===**
For more details, see test/snapshots
See Releases page.
Install devDependencies and Run npm test
:
npm i -d && npm test
./snapshots/<name>/
input.txt
and input-patterns.json
npm run test:updateSnapshot
npm test
and pass itPull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © azu
FAQs
Regexp-like string matcher.
The npm package @textlint/regexp-string-matcher receives a total of 85,444 weekly downloads. As such, @textlint/regexp-string-matcher popularity was classified as popular.
We found that @textlint/regexp-string-matcher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.