Regular Expressions 101

Community Patterns

21

Get path from any text

Created·2023-01-31 14:38
Updated·2023-07-23 20:17
Flavor·PCRE2 (PHP)
Recommended·
Get path (windows style) from any type of text (error message, e-mail corps ...), quoted or not. THIS IS THE SINGLE LINE VERSION ! If you want understand how it work or edit it, go https://regex101.com/r/7o2fyy Relative path are not supported The goal is to catch what "Look like" a path. See the limitations UNC path and prefix path like //./], [//?/] or [//./UNC/] are allowed some url path like [file:///C:/] or [file://] are allowed Catch path quoted with ["] and [']. But these quotes are include with the catch Quoted path is not concerned by limitations Limitations : (only unquoted path) [dot] and [space] is allowed, but not in a row [dot+space] or [space+dot at end of file name isn't catched INSIDE A NAME FILE (or last directory if it is a path to a directory) : [comma] is not supported (it stop the catch) after a first [dot], any [space] stop the catch after a [space], catch is stoped if next character is not a [letter], [digit] or [-] so, double [space] stop the catch Compatibility compatible PCRE, PCRE2 AutoHotkey : don't forget to escape "%" in "`%" /!\ Powershell and .Net /!\\ : this regex need some modification to be interpreted by powershell. You have to replace each (?&CapturGroupName) by \k. Use this powershell code to do this replacement : ` $powershellRegex = @' [Put here the regex to replace (?&CapturGroupName) with \k] '@ -replace '\(\?&(\w+)\)', '\k' ` This example code must return : [Put here the regex to replace \k with \k]
Submitted by nitrateag

Community Library Entry

0

Regular Expression
Created·2019-08-09 03:15
Flavor·PCRE (Legacy)

/
职业学院|技工学院|招生代表|短期项目|背景提升|美国新闻|大专留学|专科留学|工薪家庭|在地服务|澳洲八大|卧龙岗大学|庆应义塾|浦项理工|浦项科技|成均馆|先修课程|桥梁课程|多点问|多点君|专升本|专升硕|三校生|双录取|微留学|低成本|永居|\bH1B\b|\bEB5\b|\bIB课程|\bQS排名|英国G5\b|大学(?!|||||||||||||||||||||)|小学(?!|||||||||||||||||||||)|高中(?!|||||||||||||)|初中(?!|||||||||||||)|夏校(?!|)|(?<!||||)绩点|(?<!|||||)早行动|(?<!|||||)早决定|(?<!|||)问多点|(?<!|)中学(?!|||||||||||||||||||||)|(?<!|)雅思(?!|)|(?<!||)托福(?!)|(?<!|||||)全奖(?!||||||||||)|(?<!|||)半奖(?!||||||||||)|(?<!|||||||)校代(?!|||||)|(?<!|||||||)美高(?!|||||)|(?<!|||||||)美研(?!||)|(?<!|||||||)美本(?!|||||)|(?<!|||||)考培(?!|||)|(?<!|||||||西班牙|意大利|荷兰)语培(?!|||)|(?<!|||||)考陪(?!|||||)|(?<!|||||||西班牙|意大利|荷兰)语陪(?!|||||)|(?<!||||)申研(?!)|(?<!||||)申博(?!||)|(?<!||||)直申(?!|||||||)|(?<!|||)地接(?!||||||||||)|(?<!|||||)工签(?!|||||||)|(?<!|||||张家|自由|舟山)港大(?!|||||||||||)|(?<!||)墨大(?!|||||||||||)|(?<!|||)庆大(?!|||||||||||)|(?<!||||||)庆应(?!)|(?<!||)延大(?!|||||||||||)|(?<!||)延世(?!)|(?<!||||||)庆熙(?!)|(?<!||||||西)药学(?!|||||||||||||||||||||)|(?<!)高商(?!||||||||||||||||||||)
/
ig
Open regex in editor

Description

解决NLP分词无法识别留学行业专属词汇的问题

Submitted by anonymous